<!DOCTYPE html>
<!-- Generated Jan 12 2022 -->
<!-- YAML source: https://github.com/shygoo/pj64d-docs -->
<head>
<title>Project64 JavaScript API 2022.01.12</title>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,400italic,700,700italic' rel='stylesheet' type='text/css'>
<style>
:root {
    --clr-bg0: #EEE;
    --clr-bg1: #FFF;
    --clr-bg2: #DDD;
    --clr-bg3: #CCC;
    --clr-bg4: #BBB;
    --clr-text: #222;
    --clr-hr: #ECC;
    --clr-link: #090;
    --clr-link-hover: #070;
    --clr-link-unstable: #990;
    --clr-link-unstable-hover: #770;
    --clr-highlight: #DFD;
    --clr-tag-blue: #8AD;
    --clr-tag-red: #D77;
    --clr-js-keyword: #22F;
    --clr-js-string: #880;
    --clr-js-number: #722;
    --clr-js-comment: #272;
    --clr-js-word: #222;
    --clr-js-etc: #666;
}

[data-theme="dark"] {
    --clr-bg0: #222;
    --clr-bg1: #2A2A2A;
    --clr-bg2: #444;
    --clr-bg3: #555;
    --clr-bg4: #666;
    --clr-text: #FFF;
    --clr-hr: #744;
    --clr-link: #8D8;
    --clr-link-hover: #7C7;
    --clr-link-unstable: #DD8;
    --clr-link-unstable-hover: #CC7;
    --clr-highlight: #252;
    --clr-tag-blue: #247;
    --clr-tag-red: #722;
    --clr-js-keyword: #67F;
    --clr-js-string: #FFA;
    --clr-js-number: #FAA;
    --clr-js-comment: #7A7;
    --clr-js-word: #FFF;
    --clr-js-etc: #AAA;
}

*::-webkit-scrollbar {
    background: #FFF;
    background: var(--clr-bg1);
    border: 1px solid #FFF;
    border-color: var(--clr-bg1);
    width: 1.2em;
    padding: 2px;
    margin: 2px;
}

*::-webkit-scrollbar-thumb {
    background: #DDD;
    background: var(--clr-bg2);
    border: 2px solid #FFF;
    border-color: var(--clr-bg1);
}

*::-webkit-scrollbar-thumb:hover {
    background: #CCC;
    background: var(--clr-bg3);
}

*::-webkit-scrollbar-thumb:active {
    background: #BBB;
    background: var(--clr-bg4);
}

body {
    margin: 0px;
    background: #EEE;
    background: var(--clr-bg0);
    font-family: 'Open Sans', sans-serif;
    font-size: 14px;
    color: #222;
    color: var(--clr-text);
}

a {
    color: #090;
    color: var(--clr-link);
    text-decoration: none;
}

a:hover {
    color: #070;
    color: var(--clr-link-hover);
}

table {
    border-collapse: collapse;
    border-spacing: 0px;
    font-size: inherit;
}

thead {
    font-weight: bold;
    background: #EEE;
    background: var(--clr-bg0);
}

td {
    border: 1px solid #CCC;
    border-color: var(--clr-bg3);
    padding: 2px 6px;
}

ul {
    color: #222;
    color: var(--clr-text);
    padding-inline-start: 20px;
}

hr {
    border: none;
    border-top: 1px solid #ECC;
    border-color: var(--clr-hr);
}

div.pagetitle {
    font-size: 1.5em;
    font-weight: bold;
}

div.module {
    border-top: 1px solid #ECC;
    border-color: var(--clr-hr);
    padding: 20px;
    margin-bottom: 10px;
    background: #FFF;
    background: var(--clr-bg1);
}

div.modtitle {
    font-size: 2em;
    font-weight: bold;
}

div.prop {
    border-top: 1px solid #DDD;
    border-color: var(--clr-bg2);
    padding-top: 20px;
    margin-top: 20px;
    font-size: 1.3em;
    font-weight: bold;
}

span.title:target {
    background: #DFD;
    background: var(--clr-highlight);
}

span.title2 {
    font-size: 1.3em;
    font-weight: bold;
}

div.tsproto {
    font-size: 0.8em;
    font-family: monospace;
}

div.desc {
    margin-top: 10px;
    padding: 5px;
}

span.snip {
    display: inline-block;
    background: #EEE;
    background: var(--clr-bg0);
    font-family: monospace;
    padding-left: 2px;
    padding-right: 2px;
}

div.tag {
    float:right;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: normal;
}

div.tag.blue {
    background: #8AD;
    background: var(--clr-tag-blue);
}

div.tag.red {
    background: #D77;
    background: var(--clr-tag-red);
}

div.sidebar {
    width: 440px;
    position: fixed;
    top: 0px;
    left: 0px;
    bottom: 0px;
    overflow-y: auto;
    background: #FFF;
    background: var(--clr-bg1);
}

div.sidebar-content {
    font-size: 13px;
    padding: 10px;
}

div.content {
    margin-left: 440px;
    padding: 10px;
}

pre.ex {
    margin-top: 10px;
    padding: 10px;
    font-family: monospace;
    font-size: 0.9em;
    background: #EEE;
    background: var(--clr-bg0);
    color: #666;
    color: var(--clr-js-etc);
    white-space: pre-wrap;
}

a.unstable {
    color: var(--clr-link-unstable);
}

a.unstable:hover {
    color: var(--clr-link-unstable-hover);
}

span.js-keyword { color: #22F; color: var(--clr-js-keyword); }
span.js-string { color: #880; color: var(--clr-js-string); }
span.js-number { color: #722; color: var(--clr-js-number); }
span.js-comment { color: #272; color: var(--clr-js-comment); }
span.js-word { color: #222; color: var(--clr-js-word); }
</style>
<script>
if(localStorage && localStorage.getItem('theme')) {
    document.documentElement.setAttribute('data-theme', localStorage.getItem('theme'));
}
else if(window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
    document.documentElement.setAttribute('data-theme', 'dark');
}

window.addEventListener('load', function() {
    if(document.documentElement.getAttribute('data-theme') == 'dark') {
        document.querySelector('#darkmode-toggle').checked = true;
    }
    
    document.querySelector('#darkmode-toggle').onchange = function(e) {
        var theme = e.target.checked ? 'dark' : 'default';
        document.documentElement.setAttribute('data-theme', theme);
        if(localStorage) {
            localStorage.setItem('theme', theme);
        }
    }
});

</script>
</head>
<body>
<div class="sidebar">
<div class="sidebar-content">
<div class="pagetitle">Project64 JavaScript API</div>
2022.01.12
<hr>
<ul>
<p><li><a class="" href="#Project64 JavaScript API">Project64 JavaScript API</a><ul>
<li><a class="" href="#Required_settings">Required settings</a></li>
<li><a class="" href="#Script_console">Script console</a></li>
<li><a class="" href="#JavaScript_environment">JavaScript environment</a></li>
</ul></li></p>
<p><li><a class="" href="#console">console</a>: Console interface<ul>
<li><a class="" href="#console_log">console.log(message[, ...])</a></li>
<li><a class="" href="#console_print">console.print(message[, ...])</a></li>
<li><a class="" href="#console_error">console.error(err)</a></li>
<li><a class="" href="#console_clear">console.clear()</a></li>
<li><a class="" href="#console_listen">console.listen(inputListener)</a></li>
</ul></li></p>
<p><li><a class="" href="#pj64">pj64</a>: Project64 interface<ul>
<li><a class="" href="#pj64_open">pj64.open(romPath)</a></li>
<li><a class="" href="#pj64_close">pj64.close()</a></li>
<li><a class="" href="#pj64_reset">pj64.reset([soft])</a></li>
<li><a class="" href="#pj64_pause">pj64.pause()</a></li>
<li><a class="" href="#pj64_resume">pj64.resume()</a></li>
<li><a class="" href="#pj64_limitfps">pj64.limitfps(limitFps)</a></li>
<li><a class="" href="#pj64_installDirectory">pj64.installDirectory</a></li>
<li><a class="" href="#pj64_scriptsDirectory">pj64.scriptsDirectory</a></li>
<li><a class="" href="#pj64_modulesDirectory">pj64.modulesDirectory</a></li>
<li><a class="" href="#pj64_romDirectory">pj64.romDirectory</a></li>
<li><a class="" href="#pj64_romInfo">pj64.romInfo</a></li>
</ul></li></p>
<p><li><a class="" href="#mem">mem</a>: N64 memory interface<ul>
<li><a class="" href="#mem__">mem.u8|u16|u32|s8|s16|s32|f32|f64</a></li>
<li><a class="" href="#mem_bindvar">mem.bindvar(object, address, name, typeId)</a></li>
<li><a class="" href="#mem_bindvars">mem.bindvars(object, vars)</a></li>
<li><a class="" href="#mem_bindstruct">mem.bindstruct(object, address, properties)</a></li>
<li><a class="" href="#mem_typedef">mem.typedef(properties)</a></li>
<li><a class="" href="#mem_getblock">mem.getblock(address, length)</a></li>
<li><a class="" href="#mem_setblock">mem.setblock(address, data[, length])</a></li>
<li><a class="" href="#mem_getstring">mem.getstring(address[, length])</a></li>
<li><a class="" href="#mem_setstring">mem.setstring(address, data[, length])</a></li>
<li><a class="" href="#mem_ramSize">mem.ramSize</a></li>
<li><a class="" href="#mem_romSize">mem.romSize</a></li>
<li><a class="" href="#mem_ptr">mem.ptr</a></li>
</ul></li></p>
<p><li><a class="" href="#events">events</a>: Event hooking interface<ul>
<li><a class="" href="#events_onstatechange">events.onstatechange(callback)</a></li>
<li><a class="" href="#EmuStateChangeEvent">EmuStateChangeEvent</a></li>
<li><a class="" href="#events_onexec">events.onexec(address, callback)</a></li>
<li><a class="" href="#CPUExecEvent">CPUExecEvent</a></li>
<li><a class="" href="#events_onread">events.onread(address, callback)</a></li>
<li><a class="" href="#events_onwrite">events.onwrite(address, callback)</a></li>
<li><a class="" href="#CPUReadWriteEvent">CPUReadWriteEvent</a></li>
<li><a class="" href="#events_onopcode">events.onopcode(address, opcode, mask, callback)</a></li>
<li><a class="" href="#CPUOpcodeEvent">CPUOpcodeEvent</a></li>
<li><a class="" href="#events_ongprvalue">events.ongprvalue(address, regFlags, value, callback)</a></li>
<li><a class="" href="#GPR_flags">General purpose register flags</a></li>
<li><a class="" href="#CPURegValueEvent">CPURegValueEvent</a></li>
<li><a class="" href="#events_onpifread">events.onpifread(callback)</a></li>
<li><a class="" href="#GenericEvent">GenericEvent</a></li>
<li><a class="" href="#events_onsptask">events.onsptask(callback)</a></li>
<li><a class="" href="#SPTaskEvent">SPTaskEvent</a></li>
<li><a class="" href="#events_onpidma">events.onpidma(callback)</a></li>
<li><a class="" href="#PIEvent">PIEvent</a></li>
<li><a class="" href="#events_onmousedown">events.onmousedown(callback)</a></li>
<li><a class="" href="#events_onmouseup">events.onmouseup(callback)</a></li>
<li><a class="" href="#events_onmousemove">events.onmousemove(callback)</a></li>
<li><a class="" href="#MouseEvent">MouseEvent</a></li>
<li><a class="" href="#events_remove">events.remove(callbackId)</a></li>
</ul></li></p>
<p><li><a class="" href="#AddressRange">AddressRange</a>: Address range class<ul>
<li><a class="" href="#new_AddressRange">new AddressRange(start, end)</a></li>
<li><a class="" href="#range_size">range.size()</a></li>
<li><a class="" href="#range_includes">range.includes(address)</a></li>
<li><a class="" href="#range_offset">range.offset(address)</a></li>
<li><a class="" href="#range_address">range.address(offset)</a></li>
<li><a class="" href="#range_start">range.start</a></li>
<li><a class="" href="#range_end">range.end</a></li>
</ul></li></p>
<p><li><a class="" href="#N64Image">N64Image</a>: N64 image class<ul>
<li><a class="" href="#new_N64Image">new N64Image(width, height[, format [, pixels[, palette]]])</a></li>
<li><a class="" href="#N64Image_fromPNG">N64Image.fromPNG(pngData[, format])</a></li>
<li><a class="" href="#N64Image_format">N64Image.format(gbiFmt, gbiSiz[, gbiTlutFmt])</a></li>
<li><a class="" href="#N64Image_bpp">N64Image.bpp(format)</a></li>
<li><a class="" href="#image_toPNG">image.toPNG()</a></li>
<li><a class="" href="#image_update">image.update()</a></li>
<li><a class="" href="#image_format">image.format</a></li>
<li><a class="" href="#image_width">image.width</a></li>
<li><a class="" href="#image_height">image.height</a></li>
<li><a class="" href="#image_pixels">image.pixels</a></li>
<li><a class="" href="#image_palette">image.palette</a></li>
</ul></li></p>
<p><li><a class="" href="#cpu">cpu</a>: CPU register interface<ul>
<li><a class="" href="#cpu_pc">cpu.pc</a></li>
<li><a class="" href="#cpu_hi">cpu.hi</a></li>
<li><a class="" href="#cpu_lo">cpu.lo</a></li>
<li><a class="" href="#cpu_uhi">cpu.uhi</a></li>
<li><a class="" href="#cpu_ulo">cpu.ulo</a></li>
<li><a class="" href="#cpu_gpr__">cpu.gpr.r0|at|v0|v1..ra</a></li>
<li><a class="" href="#cpu_ugpr__">cpu.ugpr.r0|at|v0|v1..ra</a></li>
<li><a class="" href="#cpu_fpr__">cpu.fpr.f0..f31</a></li>
<li><a class="" href="#cpu_dfpr__">cpu.dfpr.f0..f30</a></li>
<li><a class="" href="#cpu_cop0">cpu.cop0.index..errorepc</a></li>
</ul></li></p>
<p><li><a class="" href="#debug">debug</a>: Debugger interface<ul>
<li><a class="" href="#debug_breakhere">debug.breakhere([silent])</a></li>
<li><a class="" href="#debug_resume">debug.resume()</a></li>
<li><a class="" href="#debug_step">debug.step()</a></li>
<li><a class="" href="#debug_skip">debug.skip()</a></li>
<li><a class="" href="#debug_showmemory">debug.showmemory(address[, physical])</a></li>
<li><a class="" href="#debug_showcommands">debug.showcommands(address)</a></li>
<li><a class="" href="#debug_paused">debug.paused</a></li>
</ul></li></p>
<p><li><a class="" href="#asm">asm</a>: ASM utilities<ul>
<li><a class="" href="#asm_encode">asm.encode(command[, address])</a></li>
<li><a class="" href="#asm_decode">asm.decode(opcode[, address])</a></li>
<li><a class="" href="#asm_gprname">asm.gprname(regIndex)</a></li>
</ul></li></p>
<p><li><a class="" href="#fs">fs</a>: File system interface<ul>
<li><a class="" href="#fs_open">fs.open(path, mode)</a></li>
<li><a class="" href="#fs_close">fs.close(fd)</a></li>
<li><a class="" href="#fs_write">fs.write(fd, buffer[, offset[, length[, position]]])</a></li>
<li><a class="" href="#fs_writefile">fs.writefile(path, buffer)</a></li>
<li><a class="" href="#fs_read">fs.read(fd, buffer, offset, length, position)</a></li>
<li><a class="" href="#fs_readfile">fs.readfile(path)</a></li>
<li><a class="" href="#fs_exists">fs.exists(path)</a></li>
<li><a class="" href="#fs_fstat">fs.fstat(fd)</a></li>
<li><a class="" href="#fs_stat">fs.stat(path)</a></li>
<li><a class="" href="#fs_unlink">fs.unlink(path)</a></li>
<li><a class="" href="#fs_mkdir">fs.mkdir(path)</a></li>
<li><a class="" href="#fs_rmdir">fs.rmdir(path)</a></li>
<li><a class="" href="#fs_readdir">fs.readdir(path)</a></li>
<li><a class="" href="#fs_Stats">fs.Stats</a></li>
</ul></li></p>
<p><li><a class="" href="#Socket">Socket</a>: TCP socket class<ul>
<li><a class="" href="#new_Socket">new Socket([options])</a></li>
<li><a class="" href="#socket_connect">socket.connect(port, host[, connectListener])</a></li>
<li><a class="" href="#socket_write">socket.write(data[, callback])</a></li>
<li><a class="" href="#socket_end">socket.end([data[, callback]])</a></li>
<li><a class="" href="#socket_close">socket.close()</a></li>
<li><a class="" href="#socket_on_connect">socket.on('connect', listener)</a></li>
<li><a class="" href="#socket_on_lookup">socket.on('lookup', listener)</a></li>
<li><a class="" href="#socket_on_data">socket.on('data', listener)</a></li>
<li><a class="" href="#socket_on_end">socket.on('end', listener)</a></li>
<li><a class="" href="#socket_on_close">socket.on('close', listener)</a></li>
<li><a class="" href="#socket_on_drain">socket.on('drain', listener)</a></li>
<li><a class="" href="#socket_on_error">socket.on('error', listener)</a></li>
<li><a class="" href="#socket_off">socket.off(eventName, listener)</a></li>
<li><a class="" href="#socket_remoteAddress">socket.remoteAddress</a></li>
<li><a class="" href="#socket_remotePort">socket.remotePort</a></li>
<li><a class="" href="#socket_localAddress">socket.localAddress</a></li>
<li><a class="" href="#socket_localPort">socket.localPort</a></li>
<li><a class="" href="#socket_addressFamily">socket.addressFamily</a></li>
</ul></li></p>
<p><li><a class="" href="#Server">Server</a>: TCP server class<ul>
<li><a class="" href="#new_Server">new Server()</a></li>
<li><a class="" href="#server_listen">server.listen(port[, address])</a></li>
<li><a class="" href="#server_close">server.close()</a></li>
<li><a class="" href="#server_on_connection">server.on('connection', listener)</a></li>
<li><a class="" href="#server_on_listening">server.on('listening', listener)</a></li>
<li><a class="" href="#server_on_close">server.on('close', listener)</a></li>
<li><a class="" href="#server_on_error">server.on('error', listener)</a></li>
<li><a class="" href="#server_off">server.off(eventName, listener)</a></li>
<li><a class="" href="#server_port">server.port</a></li>
<li><a class="" href="#server_address">server.address</a></li>
<li><a class="" href="#server_addressFamily">server.addressFamily</a></li>
</ul></li></p>
<p><li><a class="" href="#script">script</a>: Script instance configuration interface<ul>
<li><a class="" href="#script_keepalive">script.keepalive(keepAlive)</a></li>
<li><a class="" href="#script_timeout">script.timeout(milliseconds)</a></li>
<li><a class="" href="#script_abort">script.abort()</a></li>
</ul></li></p>
<p><li><a class="" href="#Globals">Globals</a><ul>
<li><a class="" href="#global">global</a></li>
<li><a class="" href="#PJ64_JSAPI_VERSION">PJ64_JSAPI_VERSION</a></li>
<li><a class="" href="#require">require(id)</a></li>
<li><a class="" href="#exec">exec(command[, options])</a></li>
<li><a class="" href="#alert">alert(message[, caption])</a></li>
<li><a class="" href="#setTimeout">setTimeout(callback, delay)</a></li>
<li><a class="" href="#clearTimeout">clearTimeout(timeoutId)</a></li>
<li><a class="" href="#setInterval">setInterval(callback, delay)</a></li>
<li><a class="" href="#clearInterval">clearInterval(intervalId)</a></li>
<li><a class="" href="#number_hex">number.hex([numChars])</a></li>
<li><a class="" href="#type_ids">Type IDs</a></li>
<li><a class="" href="#N64_memory_addresses">N64 memory addresses</a></li>
<li><a class="" href="#Miscellaneous">Miscellaneous</a></li>
</ul></li></p>
</ul>
<hr>
<label style="font-size: 12px; vertical-align: middle; user-select: none;">
    <input id="darkmode-toggle" type="checkbox" style="vertical-align: bottom; margin-right: 5px;"/>
    Dark theme
</label>
</div>
</div>
<div class="content">
<!-- Project64 JavaScript API -->
<div class="module">
<div class="modtitle"><span class="title" id="Project64 JavaScript API">Project64 JavaScript API</span></div>
<!-- Required_settings -->
<p><div class="prop"><span class="title" id="Required_settings">Required settings</span></div>
</p>
<p>The following settings must be used to enable the script console.</p>
<p>Go to <i>Options &gt; Configuration</i> and uncheck <i>Hide advanced settings</i>.
Optional: You may also want to uncheck <i>Pause emulation when window is not active</i> for general debugging.</p>
<p><img src=""></p>
<p><img src=""></p>
<p>Click <i>Advanced</i>, then check <i>Enable Debugger</i>.
Optional: Check <i>Always use interpreter core</i> -- 
This is required for some of the <a href="#events">events</a> interface functions to work, but it may impact game performance.</p>
<p><img src=""></p>
<!-- Script_console -->
<p><div class="prop"><span class="title" id="Script_console">Script console</span></div>
</p>
<p>Go to <i>Debugger > Scripts...</i> to open the script console.</p>
<p><img src=""></p>
<p><img src=""></p>
<p>You can view the scripts directory in the file explorer by clicking the <span class="snip">...</span> button.
JavaScript (<span class="snip">*.js</span>) files in the root of this directory are visible to the console.</p>
<p>A script may be toggled by double clicking it, or selecting it and then clicking the <i>Run/Stop</i> button.</p>
<p>While a script is active you may select it and enter code in the input box at the bottom of of the window.
Entered code is evaluated in the selected script's instance (namespace is not shared between instances).
You can use the up and down arrow keys to scroll through input history.</p>
<p>You may configure a script to run automatically when Project64 is started by right clicking it and clicking <i>Autorun...</i></p>
<p><img src=""></p>
<!-- JavaScript_environment -->
<p><div class="prop"><span class="title" id="JavaScript_environment">JavaScript environment</span></div>
</p>
<p>Project64's script system uses the <a target="blank" href="https://duktape.org/">Duktape JavaScript engine</a>. Duktape supports ECMAScript E5 and some features from ES2015+.</p>
<ul>
<li><a target="blank" href="https://wiki.duktape.org/postes5features">Post-ES5 features</a></li>
<li><a target="blank" href="https://duktape.org/guide.html#duktapebuiltins">Duktape built-ins</a></li>
</ul>

</div>
<!-- console -->
<div class="module">
<div class="modtitle"><span class="title" id="console">console</span></div>
Console interface
<!-- console_log -->
<p><div class="prop"><span class="title" id="console_log">console.log(message[, ...])</span></div>
<div class="tsproto">console.log(message: any, ...optionalParams): void</div>
</p>
Prints all provided arguments to the console with a trailing newline.
<pre class="ex">
<span class="js-word">console</span>.<span class="js-word">log</span>(<span class="js-string">"Hello"</span>, <span class="js-string">"world!"</span>);
</pre>
<!-- console_print -->
<p><div class="prop"><span class="title" id="console_print">console.print(message[, ...])</span></div>
<div class="tsproto">console.print(message: any, ...optionalParams): void</div>
</p>
Prints all provided arguments to the console.
<pre class="ex">
<span class="js-word">console</span>.<span class="js-word">print</span>(<span class="js-string">"Hello "</span>);
<span class="js-word">console</span>.<span class="js-word">print</span>(<span class="js-string">"world!\n"</span>);
</pre>
<!-- console_error -->
<p><div class="prop"><span class="title" id="console_error">console.error(err)</span></div>
<div class="tsproto">console.print(err: Error): void</div>
</p>
Prints the stack property of an error object.
<!-- console_clear -->
<p><div class="prop"><span class="title" id="console_clear">console.clear()</span></div>
<div class="tsproto">console.clear(): void</div>
</p>
Clears the console.
<!-- console_listen -->
<p><div class="prop"><span class="title" id="console_listen">console.listen(inputListener)</span></div>
<div class="tsproto">console.listen(inputListener: null | (input: string) => void): void</div>
</p>
<p>Overrides the default input behavior; console input will be passed to <span class="snip">inputListener</span> instead of being evaluated as JS code.</p>

<p>The listener may be unset by calling <span class="snip">console.listen(null)</span>.</p>
<pre class="ex">
<span class="js-word">console</span>.<span class="js-word">listen</span>(<span class="js-keyword">function</span>(<span class="js-word">input</span>) {
    <span class="js-keyword">var</span> <span class="js-word">args</span> = <span class="js-word">input</span>.<span class="js-word">split</span>(<span class="js-string">" "</span>);
    <span class="js-keyword">var</span> <span class="js-word">command</span> = <span class="js-word">args</span>.<span class="js-word">shift</span>();
    <span class="js-keyword">switch</span>(<span class="js-word">command</span>) {
    <span class="js-keyword">case</span> <span class="js-string">"ping"</span>:
        <span class="js-word">console</span>.<span class="js-word">log</span>(<span class="js-string">"pong (args were:"</span>, <span class="js-word">args</span>.<span class="js-word">join</span>(<span class="js-string">", "</span>), <span class="js-string">")"</span>);
        <span class="js-keyword">return</span>;
    <span class="js-keyword">case</span> <span class="js-string">"end"</span>:
        <span class="js-word">console</span>.<span class="js-word">log</span>(<span class="js-string">"done"</span>);
        <span class="js-word">console</span>.<span class="js-word">listen</span>(<span class="js-keyword">null</span>);
        <span class="js-keyword">return</span>;
    <span class="js-keyword">default</span>:
        <span class="js-word">console</span>.<span class="js-word">log</span>(<span class="js-string">"unknown command '"</span> + <span class="js-word">command</span> + <span class="js-string">"'"</span>);
    }
});
</pre>

</div>
<!-- pj64 -->
<div class="module">
<div class="modtitle"><span class="title" id="pj64">pj64</span></div>
Project64 interface
<!-- pj64_open -->
<p><div class="prop"><span class="title" id="pj64_open">pj64.open(romPath)</span></div>
<div class="tsproto">pj64.open(romPath: string): void</div>
</p>
Opens a ROM.
<!-- pj64_close -->
<p><div class="prop"><span class="title" id="pj64_close">pj64.close()</span></div>
<div class="tsproto">pj64.close(): void</div>
</p>
Closes the current ROM.
<!-- pj64_reset -->
<p><div class="prop"><span class="title" id="pj64_reset">pj64.reset([soft])</span></div>
<div class="tsproto">pj64.reset(soft?: boolean = false): void</div>
</p>
Resets emulation. Performs a soft reset if <span class="snip">soft</span> is true.
<!-- pj64_pause -->
<p><div class="prop"><span class="title" id="pj64_pause">pj64.pause()</span></div>
<div class="tsproto">pj64.pause(): void</div>
</p>
Pauses emulation.
<!-- pj64_resume -->
<p><div class="prop"><span class="title" id="pj64_resume">pj64.resume()</span></div>
<div class="tsproto">pj64.resume(): void</div>
</p>
Resumes emulation.
<!-- pj64_limitfps -->
<p><div class="prop"><span class="title" id="pj64_limitfps">pj64.limitfps(limitFps)</span></div>
<div class="tsproto">pj64.limitfps(limitFps: boolean): void</div>
</p>
Enables or disables the FPS limit.
<!-- pj64.installDirectory -->
<p><div class="prop"><span class="title" id="pj64_installDirectory">pj64.installDirectory</span></div>
<div class="tsproto">pj64.installDirectory: string</div>
</p>
Path to the directory containing the Project64 executable. Read-only.
<!-- pj64.scriptsDirectory -->
<p><div class="prop"><span class="title" id="pj64_scriptsDirectory">pj64.scriptsDirectory</span></div>
<div class="tsproto">pj64.scriptsDirectory: string</div>
</p>
Path to the scripts directory. Read-only.
<!-- pj64.modulesDirectory -->
<p><div class="prop"><span class="title" id="pj64_modulesDirectory">pj64.modulesDirectory</span></div>
<div class="tsproto">pj64.modulesDirectory: string</div>
</p>
Path to the script modules directory. Read-only.
<!-- pj64.romDirectory -->
<p><div class="prop"><span class="title" id="pj64_romDirectory">pj64.romDirectory</span></div>
<div class="tsproto">pj64.romDirectory: string</div>
</p>
<p>Path to the current ROM directory. Read-only.</p>
<!-- pj64.romInfo -->
<p><div class="prop"><span class="title" id="pj64_romInfo">pj64.romInfo</span></div>
<div class="tsproto">pj64.romInfo: null | Object</div>
</p>
<p>Object containing information about the current ROM. <span class="snip">null</span> if no ROM is loaded.</p>
<table>
<tr><td><span class="snip">pj64.romInfo.goodName</span>       </td><td>RDB "Good Name".</td></tr>
<tr><td><span class="snip">pj64.romInfo.fileName</span>       </td><td>Name of the ROM file including the file extension.</td></tr>
<tr><td><span class="snip">pj64.romInfo.filePath</span>       </td><td>Path to the ROM file.</td></tr>
<tr><td><span class="snip">pj64.romInfo.crc1</span>           </td><td>Internal CRC 1.</td></tr>
<tr><td><span class="snip">pj64.romInfo.crc2</span>           </td><td>Internal CRC 2.</td></tr>
<tr><td><span class="snip">pj64.romInfo.name</span>           </td><td>Internal name.</td></tr>
<tr><td><span class="snip">pj64.romInfo.mediaFormat</span>    </td><td>Internal media format number.</td></tr>
<tr><td><span class="snip">pj64.romInfo.id</span>             </td><td>Internal ID character pair.</td></tr>
<tr><td><span class="snip">pj64.romInfo.countryCode</span>    </td><td>Internal country code character.</td></tr>
<tr><td><span class="snip">pj64.romInfo.version</span>        </td><td>Internal version number.</td></tr>
</table>

</div>
<!-- mem -->
<div class="module">
<div class="modtitle"><span class="title" id="mem">mem</span></div>
N64 memory interface
<!-- mem__ -->
<p><div class="prop"><span class="title" id="mem__">mem.u8|u16|u32|s8|s16|s32|f32|f64</span></div>
</p>
Arrays for reading and writing memory. Virtual addresses are used as indices.
<pre class="ex">
<span class="js-comment">// Read some data from ROM and RAM</span>
<span class="js-keyword">var</span> <span class="js-word">firstWordInROM</span> = <span class="js-word">mem</span>.<span class="js-word">u32</span>[<span class="js-number">0xB0000000</span>];
<span class="js-keyword">var</span> <span class="js-word">firstWordInRAM</span> = <span class="js-word">mem</span>.<span class="js-word">u32</span>[<span class="js-number">0x80000000</span>];
</pre>
<pre class="ex">
<span class="js-comment">// Move player to 0,0,0 (SM64 US)</span>
<span class="js-keyword">const</span> <span class="js-word">pPlayerX</span> = <span class="js-number">0x8033B1AC</span>;
<span class="js-keyword">const</span> <span class="js-word">pPlayerY</span> = <span class="js-number">0x8033B1B0</span>;
<span class="js-keyword">const</span> <span class="js-word">pPlayerZ</span> = <span class="js-number">0x8033B1B4</span>;

<span class="js-word">mem</span>.<span class="js-word">f32</span>[<span class="js-word">pPlayerX</span>] = <span class="js-number">0</span>;
<span class="js-word">mem</span>.<span class="js-word">f32</span>[<span class="js-word">pPlayerY</span>] = <span class="js-number">0</span>;
<span class="js-word">mem</span>.<span class="js-word">f32</span>[<span class="js-word">pPlayerZ</span>] = <span class="js-number">0</span>;
</pre>
<!-- mem_bindvar -->
<p><div class="prop"><span class="title" id="mem_bindvar">mem.bindvar(object, address, name, typeId)</span></div>
<div class="tsproto">mem.bindvar(object: Object, address: number, name: string, typeId: number): void</div>
</p>
Adds a memory-bound property to <span class="snip">object</span>.
Valid types are <span class="snip">u8</span>, <span class="snip">u16</span>, <span class="snip">u32</span>, <span class="snip">s8</span>, <span class="snip">s16</span>, <span class="snip">s32</span>, <span class="snip">f32</span>, <span class="snip">f64</span>.
See <a href="#type_ids">Type IDs</a> for more details.
<pre class="ex">
<span class="js-word">mem</span>.<span class="js-word">bindvar</span>(<span class="js-word">global</span>, <span class="js-number">0x8033B1AC</span>, <span class="js-string">'playerX'</span>, <span class="js-word">f32</span>);
<span class="js-word">mem</span>.<span class="js-word">bindvar</span>(<span class="js-word">global</span>, <span class="js-number">0x8033B1B0</span>, <span class="js-string">'playerY'</span>, <span class="js-word">f32</span>);
<span class="js-word">mem</span>.<span class="js-word">bindvar</span>(<span class="js-word">global</span>, <span class="js-number">0x8033B1B4</span>, <span class="js-string">'playerZ'</span>, <span class="js-word">f32</span>);

<span class="js-word">console</span>.<span class="js-word">log</span>(<span class="js-string">"Player's coordinates are "</span>, <span class="js-word">playerX</span>, <span class="js-word">playerY</span>, <span class="js-word">playerZ</span>);
</pre>
<!-- mem_bindvars -->
<p><div class="prop"><span class="title" id="mem_bindvars">mem.bindvars(object, vars)</span></div>
<div class="tsproto">mem.bindvars(object: Object, vars: any[]): Object</div>
</p>
<p>Adds multiple memory-bound properties to <span class="snip">object</span>.
<span class="snip">vars</span> must be an array in which each item is an array containing an address, name, and <a href="#type_ids">type ID</a> (in order) describing a variable.</p>

<p>Returns <span class="snip">object</span>.</p>
<pre class="ex">
<span class="js-word">mem</span>.<span class="js-word">bindvars</span>(<span class="js-word">global</span>, [
    [ <span class="js-number">0x8033B1AC</span>, <span class="js-string">'playerX'</span>, <span class="js-word">f32</span> ],
    [ <span class="js-number">0x8033B1B0</span>, <span class="js-string">'playerY'</span>, <span class="js-word">f32</span> ],
    [ <span class="js-number">0x8033B1B4</span>, <span class="js-string">'playerZ'</span>, <span class="js-word">f32</span> ]
]);

<span class="js-word">console</span>.<span class="js-word">log</span>(<span class="js-string">"Player's coordinates are "</span>, <span class="js-word">playerX</span>, <span class="js-word">playerY</span>, <span class="js-word">playerZ</span>);
</pre>
<!-- mem_bindstruct -->
<p><div class="prop"><span class="title" id="mem_bindstruct">mem.bindstruct(object, address, properties)</span></div>
<div class="tsproto">mem.bindstruct(object: Object, address: number, properties: Object): Object</div>
</p>
<p>Adds multiple memory-bound properties to <span class="snip">object</span>.
<span class="snip">properties</span> must be an object in which each key/value pair specifies the name and <a href="#type_ids">type ID</a> of a variable.</p>

<p>Returns <span class="snip">object</span>.</p>
<pre class="ex">
<span class="js-keyword">var</span> <span class="js-word">playerPos</span> = <span class="js-word">mem</span>.<span class="js-word">bindstruct</span>({}, <span class="js-number">0x8033B1AC</span>, { <span class="js-word">x</span>: <span class="js-word">f32</span>, <span class="js-word">y</span>: <span class="js-word">f32</span>, <span class="js-word">z</span>: <span class="js-word">f32</span> });
<span class="js-word">console</span>.<span class="js-word">log</span>(<span class="js-string">"Player's coordinates are "</span>, <span class="js-word">playerPos</span>.<span class="js-word">x</span>, <span class="js-word">playerPos</span>.<span class="js-word">y</span>, <span class="js-word">playerPos</span>.<span class="js-word">z</span>);
</pre>
<!-- mem_typedef -->
<p><div class="prop"><span class="title" id="mem_typedef">mem.typedef(properties)</span></div>
<div class="tsproto">mem.typedef(properties: Object): MemTypeConstructor</div>
</p>
Returns a constructor function that will create an object representing a structure in memory, given its address.
<pre class="ex">
<span class="js-keyword">const</span> <span class="js-word">vec3f</span> = <span class="js-word">mem</span>.<span class="js-word">typedef</span>({ <span class="js-word">x</span>: <span class="js-word">f32</span>, <span class="js-word">y</span>: <span class="js-word">f32</span>, <span class="js-word">z</span>: <span class="js-word">f32</span> });
<span class="js-keyword">var</span> <span class="js-word">playerAngle</span> = <span class="js-keyword">new</span> <span class="js-word">vec3f</span>(<span class="js-number">0x8033B19C</span>);
<span class="js-keyword">var</span> <span class="js-word">playerPos</span> = <span class="js-keyword">new</span> <span class="js-word">vec3f</span>(<span class="js-number">0x8033B1AC</span>);
</pre>
<!-- mem_getblock -->
<p><div class="prop"><span class="title" id="mem_getblock">mem.getblock(address, length)</span></div>
<div class="tsproto">mem.getblock(address: number, length: number): Buffer</div>
</p>
Returns a block of data from memory as a <a target="blank" href="https://nodejs.org/docs/v0.12.1/api/buffer.html">Buffer</a> object.
<pre class="ex">
<span class="js-word">fs</span>.<span class="js-word">writefile</span>(<span class="js-string">"ram_dump.bin"</span>, <span class="js-word">mem</span>.<span class="js-word">getblock</span>(<span class="js-word">K0BASE</span>, <span class="js-word">mem</span>.<span class="js-word">ramSize</span>));
</pre>
<!-- mem_setblock -->
<p><div class="prop"><span class="title" id="mem_setblock">mem.setblock(address, data[, length])</span></div>
<div class="tsproto">mem.setblock(address: number, data: string | Buffer | TypedArray, length?: number): void</div>
</p>
Writes a block of data into memory. <span class="snip">data</span> may be one of the following types&#58;
<a target="blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer">ArrayBuffer</a>,
<a target="blank" href="https://nodejs.org/docs/v0.12.1/api/buffer.html">Buffer</a>,
<a target="blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView">DataView</a>,
<a target="blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray">TypedArray</a>, string.
<pre class="ex">
<span class="js-word">mem</span>.<span class="js-word">setblock</span>(<span class="js-number">0x80400000</span>, <span class="js-word">fs</span>.<span class="js-word">readfile</span>(<span class="js-string">"textures.bin"</span>));
</pre>
<!-- mem_getstring -->
<p><div class="prop"><span class="title" id="mem_getstring">mem.getstring(address[, length])</span></div>
<div class="tsproto">mem.getblock(address: number, length?: number): string</div>
</p>
Returns a zero-terminated ASCII string from memory.
<pre class="ex">
<span class="js-keyword">const</span> <span class="js-word">romName</span> = <span class="js-word">mem</span>.<span class="js-word">getstring</span>(<span class="js-number">0xB0000020</span>, <span class="js-number">0x14</span>);
</pre>
<!-- mem_setstring -->
<p><div class="prop"><span class="title" id="mem_setstring">mem.setstring(address, data[, length])</span></div>
<div class="tsproto">mem.setstring(address: number, data: string | Buffer | TypedArray, length?: number): void</div>
</p>
Writes a string into memory (alias of <a href="#mem_setblock">mem.setblock</a>).
<!-- mem_ramSize -->
<p><div class="prop"><span class="title" id="mem_ramSize">mem.ramSize</span></div>
<div class="tsproto">mem.ramSize: number</div>
</p>
The size of RDRAM in bytes. <span class="snip">0</span> if RDRAM is not initialized.
<!-- mem_romSize -->
<p><div class="prop"><span class="title" id="mem_romSize">mem.romSize</span></div>
<div class="tsproto">mem.romSize: number</div>
</p>
The size of cartridge ROM in bytes. <span class="snip">0</span> if ROM is not initialized.
<!-- mem_ptr -->
<p><div class="prop"><span class="title" id="mem_ptr">mem.ptr</span></div>
<div class="tsproto">mem.ptr: pointer</div>
</p>
Native pointer to Project64's N64 memory buffer. May be used by native modules for faster memory access.
<pre class="ex">
<span class="js-comment">// C</span>
<span class="js-word">duk_ret_t</span> <span class="js-word">example</span>(<span class="js-word">duk_context</span>* <span class="js-word">ctx</span>)
{
    <span class="js-word">uint8_t</span>* <span class="js-word">memory</span> = <span class="js-word">NULL</span>;
    <span class="js-word">duk_get_global_string</span>(<span class="js-word">ctx</span>, <span class="js-string">"mem"</span>);
    <span class="js-word">duk_get_prop_string</span>(<span class="js-word">ctx</span>, -<span class="js-number">1</span>, <span class="js-string">"ptr"</span>);
    <span class="js-word">memory</span> = <span class="js-word">duk_get_pointer</span>(<span class="js-word">ctx</span>, -<span class="js-number">1</span>);
    <span class="js-word">duk_pop_n</span>(<span class="js-word">ctx</span>, <span class="js-number">3</span>);
    <span class="js-comment">// do something to memory here</span>
    <span class="js-keyword">return</span> <span class="js-number">0</span>;
}
</pre>

</div>
<!-- events -->
<div class="module">
<div class="modtitle"><span class="title" id="events">events</span></div>
Event hooking interface
<!-- events_onstatechange -->
<p><div class="prop"><span class="title" id="events_onstatechange">events.onstatechange(callback)</span></div>
<div class="tsproto">events.onstatechange(callback: (e: EmuStateChangeEvent) => void): number</div>
</p>
Registers a callback that is invoked when the state of the emulator changes.
<span class="snip">callback</span> receives an <a href="#EmuStateChangeEvent">EmuStateChangeEvent</a> object.
<p>Returns a callback ID.</p>
<!-- EmuStateChangeEvent -->
<p><div class="prop"><span class="title" id="EmuStateChangeEvent">EmuStateChangeEvent</span></div>
</p>
<p>
<table>
<tr><td><span class="snip">e.callbackId</span></td><td>ID of the callback associated with the event.</td></tr>
<tr><td><span class="snip">e.state</span></td><td>State number. See table below.</td></tr>
</table>
</p>

<table>
<tr><td><span class="snip">EMU_STARTED</span></td><td>Emulation started.</td></tr>
<tr><td><span class="snip">EMU_STOPPED</span></td><td>Emulation stopped.</td></tr>
<tr><td><span class="snip">EMU_PAUSED</span></td><td>Emulation paused.</td></tr>
<tr><td><span class="snip">EMU_RESUMED</span></td><td>Emulation resumed from a pause.</td></tr>
<tr><td><span class="snip">EMU_RESETTING</span></td><td>Emulation is resetting.</td></tr>
<tr><td><span class="snip">EMU_RESET</span></td><td>Emulation reset.</td></tr>
<tr><td><span class="snip">EMU_LOADED_ROM</span></td><td>A ROM or 64DD image has been loaded.</td></tr>
<tr><td><span class="snip">EMU_DEBUG_PAUSED</span></td><td>Emulation paused via debugger break.</td></tr>
<tr><td><span class="snip">EMU_DEBUG_RESUMED</span></td><td>Emulation resumed via the debugger.</td></tr>
</table>
<!-- events_onexec -->
<p><div class="prop"><span class="title" id="events_onexec">events.onexec(address, callback)</span><div class="tag blue">Requires interpreter core</div></div>
<div class="tsproto">events.onexec(address: number | AddressRange, callback: (e: CPUExecEvent) => void): number</div>
</p>
Registers a callback that is invoked at the beginning of a CPU step if the program counter is at <span class="snip">address</span>.
<span class="snip">address</span> may be a single address or an object containing <span class="snip">start</span> and <span class="snip">end</span> address properties (e.g. <a href="#AddressRange">AddressRange</a>).
<span class="snip">callback</span> receives a <a href="#CPUExecEvent">CPUExecEvent</a> object.
<p>Returns a callback ID.</p>
<pre class="ex">
<span class="js-comment">// SM64 US</span>
<span class="js-word">events</span>.<span class="js-word">onexec</span>(<span class="js-number">0x802CB1C0</span>, <span class="js-keyword">function</span>() {
    <span class="js-word">console</span>.<span class="js-word">log</span>(<span class="js-string">"func_802CB1C0 was called"</span>);
});
</pre>
<pre class="ex">
<span class="js-comment">// Log every CPU step</span>
<span class="js-word">events</span>.<span class="js-word">onexec</span>(<span class="js-word">ADDR_ANY</span>, <span class="js-keyword">function</span>(<span class="js-word">e</span>) {
    <span class="js-word">console</span>.<span class="js-word">log</span>(<span class="js-word">e</span>.<span class="js-word">pc</span>.<span class="js-word">hex</span>() + <span class="js-string">": "</span> + <span class="js-word">asm</span>.<span class="js-word">decode</span>(<span class="js-word">mem</span>.<span class="js-word">u32</span>[<span class="js-word">e</span>.<span class="js-word">pc</span>], <span class="js-word">e</span>.<span class="js-word">pc</span>));
});
</pre>
<!-- CPUExecEvent -->
<p><div class="prop"><span class="title" id="CPUExecEvent">CPUExecEvent</span></div>
</p>
<table>
<tr><td><span class="snip">e.callbackId</span></td><td>ID of the callback associated with the event.</td></tr>
<tr><td><span class="snip">e.pc</span></td><td>Program counter address.</td></tr>
</table>
<!-- events_onread -->
<p><div class="prop"><span class="title" id="events_onread">events.onread(address, callback)</span><div class="tag blue">Requires interpreter core</div></div>
<div class="tsproto">events.onread(address: number | AddressRange, callback: (e: CPUReadWriteEvent) => void): number</div>
</p>
Registers a callback that is invoked at the beginning of a CPU step if the CPU is going to read from <span class="snip">address</span>.
<span class="snip">address</span> may be a single address or an object containing <span class="snip">start</span> and <span class="snip">end</span> address properties (e.g. <a href="#AddressRange">AddressRange</a>).
<span class="snip">callback</span> receives a <a href="#CPUReadWriteEvent">CPUReadWriteEvent</a> object.
<p>Returns a callback ID.</p>
<!-- events_onwrite -->
<p><div class="prop"><span class="title" id="events_onwrite">events.onwrite(address, callback)</span><div class="tag blue">Requires interpreter core</div></div>
<div class="tsproto">events.onwrite(address: number | AddressRange, callback: (e: CPUReadWriteEvent) => void): number</div>
</p>
Registers a callback that is invoked at the beginning of a CPU step if the CPU is going to write to <span class="snip">address</span>.
<span class="snip">address</span> may be a single address or an object containing <span class="snip">start</span> and <span class="snip">end</span> address properties (e.g. <a href="#AddressRange">AddressRange</a>).
<span class="snip">callback</span> receives a <a href="#CPUReadWriteEvent">CPUReadWriteEvent</a> object.
<p>Returns a callback ID.</p>
<!-- CPUReadWriteEvent -->
<p><div class="prop"><span class="title" id="CPUReadWriteEvent">CPUReadWriteEvent</span></div>
</p>
<p>
    <table>
    <tr><td><span class="snip">e.callbackId</span></td><td>ID of the callback associated with the event.</td></tr>
    <tr><td><span class="snip">e.pc</span></td><td>Program counter address.</td></tr>
    <tr><td><span class="snip">e.address</span></td><td>Address that the CPU is going to read/write.</td></tr>
    <tr><td><span class="snip">e.fpu</span></td><td><span class="snip">true</span> if the source/destination register is on the floating point unit.</td></tr>
    <tr><td><span class="snip">e.reg</span></td><td>Index of the source/destination register.</td></tr>
    <tr><td><span class="snip">e.valueType</span></td><td>The value's <a href="#type_ids">type ID</a>. Varies depending on the opcode; refer to the table below.</td></tr>
    <tr><td><span class="snip">e.value</span></td><td>Value that the CPU is going to read/write.</td></tr>
    <tr><td><span class="snip">e.valueHi</span></td><td>Upper 32 bits of the value if <span class="snip">e.valueType</span> is <span class="snip">u64</span>; otherwise <span class="snip">undefined</span>.</td></tr>
    </table>
</p>
<p>
  <table>
  <thead><tr><td><b>e.valueType</b></td><td><b>Opcode(s)</b></td></tr></thead>
  <tr><td><span class="snip">s8</span></td><td>LB, SB</td></tr>
  <tr><td><span class="snip">u8</span></td><td>LBU</td></tr>
  <tr><td><span class="snip">s16</span></td><td>LH, SH</td></tr>
  <tr><td><span class="snip">u16</span></td><td>LHU</td></tr>
  <tr><td><span class="snip">s32</span></td><td>LL, LW, LWL, LWR, SW, SWL, SWR</td></tr>
  <tr><td><span class="snip">u32</span></td><td>LWU</td></tr>
  <tr><td><span class="snip">u64</span></td><td>LD, LDL, LDR, SD, SDL, SDR</td></tr>
  <tr><td><span class="snip">f32</span></td><td>LWC1, SWC1</td></tr>
  <tr><td><span class="snip">f64</span></td><td>LDC1, SDC1</td></tr>
  </table>
</p>
<!-- events_onopcode -->
<p><div class="prop"><span class="title" id="events_onopcode">events.onopcode(address, opcode, mask, callback)</span><div class="tag blue">Requires interpreter core</div></div>
<div class="tsproto">events.onopcode(address: number | AddressRange, opcode: number, mask: number, callback: (e: CPUOpcodeEvent) => void): number</div>
</p>
Registers a callback that is invoked at the beginning of a CPU step if the program counter is at <span class="snip">address</span> and
<span class="snip">opcode</span> is equal to the current opcode ANDed with <span class="snip">mask</span>.
<span class="snip">callback</span> receives a <a href="#CPUOpcodeEvent">CPUOpcodeEvent</a> object.
<p>Returns a callback ID.</p>
<pre class="ex">
<span class="js-comment">// Log every JAL</span>
<span class="js-keyword">const</span> <span class="js-word">JAL</span> = <span class="js-word">asm</span>.<span class="js-word">encode</span>(<span class="js-string">"jal 0"</span>);
<span class="js-keyword">const</span> <span class="js-word">ANY_TARGET</span> = <span class="js-number">0xFC000000</span>; <span class="js-comment">// Mask off target field</span>
<span class="js-word">events</span>.<span class="js-word">onopcode</span>(<span class="js-word">ADDR_ANY</span>, <span class="js-word">JAL</span>, <span class="js-word">ANY_TARGET</span>, <span class="js-keyword">function</span>(<span class="js-word">e</span>) {
    <span class="js-word">console</span>.<span class="js-word">log</span>(<span class="js-word">e</span>.<span class="js-word">pc</span>.<span class="js-word">hex</span>() + <span class="js-string">": "</span> + <span class="js-word">asm</span>.<span class="js-word">decode</span>(<span class="js-word">mem</span>.<span class="js-word">u32</span>[<span class="js-word">e</span>.<span class="js-word">pc</span>], <span class="js-word">e</span>.<span class="js-word">pc</span>));
});
</pre>
<!-- CPUOpcodeEvent -->
<p><div class="prop"><span class="title" id="CPUOpcodeEvent">CPUOpcodeEvent</span></div>
</p>
<table>
<tr><td><span class="snip">e.callbackId</span></td><td>ID of the callback associated with the event.</td></tr>
<tr><td><span class="snip">e.pc</span></td><td>Program counter address.</td></tr>
<tr><td><span class="snip">e.opcode</span></td><td>The opcode.</td></tr>
</table>
<!-- events_ongprvalue -->
<p><div class="prop"><span class="title" id="events_ongprvalue">events.ongprvalue(address, regFlags, value, callback)</span><div class="tag blue">Requires interpreter core</div></div>
<div class="tsproto">events.ongprvalue(address: number | AddressRange, regFlags: number, value: number, callback: (e: CPURegValueEvent) => void): number</div>
</p>
Registers a callback that is invoked at the beginning of a CPU step if the program counter is at <span class="snip">address</span> and at least one of
the general purpose registers specified by <span class="snip">regFlags</span> is equal to <span class="snip">value</span> (lower 32 bits only).
<span class="snip">callback</span> receives a <a href="#CPURegValueEvent">CPURegValueEvent</a> object.
<p>Returns a callback ID.</p>
<p>See <a href="#GPR_flags">General purpose register flags</a> for a list of valid flags. Multiple registers may be specified via bitwise OR.</p>
<pre class="ex">
<span class="js-comment">// Break when any general purpose register contains 0x49533634</span>
<span class="js-keyword">const</span> <span class="js-word">IS64_SIGNATURE</span> = <span class="js-number">0x49533634</span>;
<span class="js-word">events</span>.<span class="js-word">ongprvalue</span>(<span class="js-word">ADDR_ANY</span>, <span class="js-word">GPR_ANY</span>, <span class="js-word">IS64_SIGNATURE</span>, <span class="js-keyword">function</span>() {
    <span class="js-word">debug</span>.<span class="js-word">breakhere</span>();
});
</pre>
<!-- GPR_flags -->
<p><div class="prop"><span class="title" id="GPR_flags">General purpose register flags</span></div>
</p>
Global flags for <a href="#events_ongprvalue">events.ongprvalue</a>'s <span class="snip">regFlags</span> parameter.
<p><span class="snip">GPR_ANY</span></p>
<p><span class="snip">GPR_R0</span> <span class="snip">GPR_AT</span> <span class="snip">GPR_V0</span> <span class="snip">GPR_V1</span> <span class="snip">GPR_A0</span> <span class="snip">GPR_A1</span> <span class="snip">GPR_A2</span> <span class="snip">GPR_A3</span></p>
<p><span class="snip">GPR_T0</span> <span class="snip">GPR_T1</span> <span class="snip">GPR_T2</span> <span class="snip">GPR_T3</span> <span class="snip">GPR_T4</span> <span class="snip">GPR_T5</span> <span class="snip">GPR_T6</span> <span class="snip">GPR_T7</span></p>
<p><span class="snip">GPR_S0</span> <span class="snip">GPR_S1</span> <span class="snip">GPR_S2</span> <span class="snip">GPR_S3</span> <span class="snip">GPR_S4</span> <span class="snip">GPR_S5</span> <span class="snip">GPR_S6</span> <span class="snip">GPR_S7</span></p>
<p><span class="snip">GPR_T8</span> <span class="snip">GPR_T9</span> <span class="snip">GPR_K0</span> <span class="snip">GPR_K1</span> <span class="snip">GPR_GP</span> <span class="snip">GPR_SP</span> <span class="snip">GPR_FP</span> <span class="snip">GPR_RA</span></p>
<!-- CPURegValueEvent -->
<p><div class="prop"><span class="title" id="CPURegValueEvent">CPURegValueEvent</span></div>
</p>
<table>
<tr><td><span class="snip">e.callbackId</span></td><td>ID of the callback associated with the event.</td></tr>
<tr><td><span class="snip">e.pc</span></td><td>Program counter address.</td></tr>
<tr><td><span class="snip">e.value</span></td><td>The value.</td></tr>
<tr><td><span class="snip">e.reg</span></td><td>Index of the register containing the value.</td></tr>
</table>
<!-- events_onpifread -->
<p><div class="prop"><span class="title" id="events_onpifread">events.onpifread(callback)</span></div>
<div class="tsproto">events.onpifread(callback: (e: GenericEvent) => void): number</div>
</p>
Registers a callback that is invoked when PIF RAM data is going to be read into RDRAM.
<span class="snip">callback</span> receives a <a href="#GenericEvent">GenericEvent</a> object.
<p>Returns a callback ID.</p>
<p>Useful for monitoring and overriding controller input.</p>
<pre class="ex">
<span class="js-comment">// Log P1's controller input</span>
<span class="js-word">events</span>.<span class="js-word">onpifread</span>(<span class="js-keyword">function</span>() {
    <span class="js-keyword">if</span>(<span class="js-word">mem</span>.<span class="js-word">u32</span>[<span class="js-word">PIF_RAM_START</span> + <span class="js-number">0x00</span>] == <span class="js-number">0xFF010401</span>) {
        <span class="js-word">console</span>.<span class="js-word">log</span>(<span class="js-word">mem</span>.<span class="js-word">u32</span>[<span class="js-word">PIF_RAM_START</span> + <span class="js-number">0x04</span>].<span class="js-word">hex</span>());
    }
});
</pre>

<pre class="ex">
<span class="js-comment">// Play an M64 TAS file</span>
<span class="js-keyword">var</span> <span class="js-word">m64file</span> = <span class="js-word">fs</span>.<span class="js-word">readfile</span>(<span class="js-string">"sm64-1key.m64"</span>);
<span class="js-keyword">var</span> <span class="js-word">numSamples</span> = <span class="js-word">m64file</span>.<span class="js-word">readUInt32LE</span>(<span class="js-number">0x018</span>);
<span class="js-keyword">var</span> <span class="js-word">sampleIndex</span> = <span class="js-number">0</span>;

<span class="js-word">events</span>.<span class="js-word">onpifread</span>(<span class="js-keyword">function</span>() {
    <span class="js-keyword">for</span>(<span class="js-keyword">var</span> <span class="js-word">nController</span> = <span class="js-number">0</span>; <span class="js-word">nController</span> < <span class="js-number">4</span>; <span class="js-word">nController</span>++) {
        <span class="js-keyword">var</span> <span class="js-word">cmdAddr</span> = <span class="js-word">PIF_RAM_START</span> + (<span class="js-word">nController</span> * <span class="js-number">8</span>);
        <span class="js-keyword">if</span>(<span class="js-word">mem</span>.<span class="js-word">u32</span>[<span class="js-word">cmdAddr</span> + <span class="js-number">0x00</span>] == <span class="js-number">0xFF010401</span> && <span class="js-word">sampleIndex</span> < <span class="js-word">numSamples</span>) {
            <span class="js-word">mem</span>.<span class="js-word">u32</span>[<span class="js-word">cmdAddr</span> + <span class="js-number">0x04</span>] = <span class="js-word">m64file</span>.<span class="js-word">readUInt32BE</span>(<span class="js-number">0x400</span> + <span class="js-word">sampleIndex</span> * <span class="js-number">4</span>);
            <span class="js-word">sampleIndex</span>++;
        }
    }
});
</pre>
<!-- GenericEvent -->
<p><div class="prop"><span class="title" id="GenericEvent">GenericEvent</span></div>
</p>
<table>
<tr><td><span class="snip">e.callbackId</span></td><td>ID of the callback associated with the event.</td></tr>
</table>
<!-- events_onsptask -->
<p><div class="prop"><span class="title" id="events_onsptask">events.onsptask(callback)</span></div>
<div class="tsproto">events.onsptask(callback: (e: SPTaskEvent) => void): number</div>
</p>
Registers a callback that is invoked when a task is sent to the RSP.
<span class="snip">callback</span> receives an <a href="#SPTaskEvent">SPTaskEvent</a> object.
<p>Returns a callback ID.</p>
<p>Useful for monitoring and overriding display lists and audio lists.</p>
<pre class="ex">
<span class="js-word">events</span>.<span class="js-word">onsptask</span>(<span class="js-keyword">function</span>(<span class="js-word">e</span>) {
    <span class="js-keyword">if</span> (<span class="js-word">e</span>.<span class="js-word">taskType</span> == <span class="js-word">M_GFXTASK</span>) {
        <span class="js-word">console</span>.<span class="js-word">log</span>(<span class="js-string">"Display list address: "</span> + <span class="js-word">e</span>.<span class="js-word">dataAddress</span>);
    }
    <span class="js-keyword">else</span> <span class="js-keyword">if</span> (<span class="js-word">e</span>.<span class="js-word">taskType</span> == <span class="js-word">M_AUDTASK</span>) {
        <span class="js-word">console</span>.<span class="js-word">log</span>(<span class="js-string">"Audio list address: "</span> + <span class="js-word">e</span>.<span class="js-word">dataAddress</span>);
    }
});
</pre>
<!-- SPTaskEvent -->
<p><div class="prop"><span class="title" id="SPTaskEvent">SPTaskEvent</span></div>
</p>
<table>
<tr><td><span class="snip">e.callbackId</span>       </td><td>ID of the callback associated with the event.</td></tr>
<tr><td><span class="snip">e.taskType</span>         </td><td>The task type. <span class="snip">M_GFXTASK</span> (1) for graphics tasks, or <span class="snip">M_AUDTASK</span> (2) for audio tasks.</td></tr>
<tr><td><span class="snip">e.taskFlags</span>        </td><td>Task flags.</td></tr>
<tr><td><span class="snip">e.ucodeBootAddress</span> </td><td>Address of the boot microcode.</td></tr>
<tr><td><span class="snip">e.ucodeBootSize</span>    </td><td>Size of the boot microcode.</td></tr>
<tr><td><span class="snip">e.ucodeAddress</span>     </td><td>Address of the task microcode.</td></tr>
<tr><td><span class="snip">e.ucodeSize</span>        </td><td>Size of the task microcode.</td></tr>
<tr><td><span class="snip">e.ucodeDataAddress</span> </td><td>Address of the microcode data.</td></tr>
<tr><td><span class="snip">e.ucodeDataSize</span>    </td><td>Size of the microcode data.</td></tr>
<tr><td><span class="snip">e.dramStackAddress</span> </td><td>Address of the DRAM matrix stack.</td></tr>
<tr><td><span class="snip">e.dramStackSize</span>    </td><td>Size of the DRAM matrix stack.</td></tr>
<tr><td><span class="snip">e.outputBuffAddress</span></td><td>DP command buffer address for "_dram" and "_fifo" graphics microcodes.</td></tr>
<tr><td><span class="snip">e.outputBuffSize</span>   </td><td>DP command buffer size for "_dram" and "_fifo" graphics microcodes.</td></tr>
<tr><td><span class="snip">e.dataAddress</span>      </td><td>Address of the display list or audio list.</td></tr>
<tr><td><span class="snip">e.dataSize</span>         </td><td>Size of the display list or audio list.</td></tr>
<tr><td><span class="snip">e.yieldDataAddress</span> </td><td>Address of the yield data buffer.</td></tr>
<tr><td><span class="snip">e.yieldDataSize</span>    </td><td>Size of the yield data buffer.</td></tr>
</table>
<p>Note: The properties of this object differ slightly from those in the DMEM OSTask structure;
all physical addresses are converted to KSEG0 addresses.</p>
<!-- events_onpidma -->
<p><div class="prop"><span class="title" id="events_onpidma">events.onpidma(callback)</span></div>
<div class="tsproto">events.onpidma(callback: (e: PIEvent) => void): number</div>
</p>
Registers a callback that is invoked when a PI DMA transfer is going to occur.
<span class="snip">callback</span> receives a <a href="#PIEvent">PIEvent</a> object.
<p>Returns a callback ID.</p>
<pre class="ex">
<span class="js-comment">// Log all cartridge <-> RDRAM data transfers</span>
<span class="js-word">events</span>.<span class="js-word">onpidma</span>(<span class="js-keyword">function</span>(<span class="js-word">e</span>) {
    <span class="js-keyword">var</span> <span class="js-word">dir</span> = <span class="js-word">e</span>.<span class="js-word">direction</span> == <span class="js-word">OS_READ</span> ? <span class="js-string">'READ'</span> : <span class="js-string">'WRITE'</span>;
    <span class="js-word">console</span>.<span class="js-word">log</span>(<span class="js-string">'[PI]'</span>, <span class="js-word">dir</span>, <span class="js-word">e</span>.<span class="js-word">dramAddress</span>.<span class="js-word">hex</span>(), <span class="js-word">e</span>.<span class="js-word">cartAddress</span>.<span class="js-word">hex</span>(), <span class="js-word">e</span>.<span class="js-word">length</span>.<span class="js-word">hex</span>());
});
</pre>
<!-- PIEvent -->
<p><div class="prop"><span class="title" id="PIEvent">PIEvent</span></div>
</p>
<table>
<tr><td><span class="snip">e.callbackId</span>  </td><td>The ID of the callback associated with the event.</td></tr>
<tr><td><span class="snip">e.direction</span>   </td><td>The direction of the DMA transfer. May be <span class="snip">OS_READ</span> (0), or <span class="snip">OS_WRITE</span> (1).</td></tr>
<tr><td><span class="snip">e.dramAddress</span> </td><td>The address in PI_DRAM_ADDR_REG (+<span class="snip">K0BASE</span>).</td></tr>
<tr><td><span class="snip">e.cartAddress</span> </td><td>The address in PI_CART_ADDR_REG (+<span class="snip">K1BASE</span>).</td></tr>
<tr><td><span class="snip">e.length</span>      </td><td>The value of PI_RD_LEN_REG or PI_WR_LEN_REG (+1), depending on the transfer direction.</td></tr>
</table>
<!-- events_onmousedown -->
<p><div class="prop"><span class="title" id="events_onmousedown">events.onmousedown(callback)</span></div>
<div class="tsproto">events.onmousedown(callback: (e: MouseEvent) => void): number</div>
</p>
Registers a callback that is invoked when a mouse button is pressed over the main screen.
<span class="snip">callback</span> receives a <a href="#MouseEvent">MouseEvent</a> object.

<p>Returns a callback ID.</p>
<!-- events_onmouseup -->
<p><div class="prop"><span class="title" id="events_onmouseup">events.onmouseup(callback)</span></div>
<div class="tsproto">events.onmouseup(callback: (e: MouseEvent) => void): number</div>
</p>
Registers a callback that is invoked when a mouse button is released over the main screen.
<span class="snip">callback</span> receives a <a href="#MouseEvent">MouseEvent</a> object.
<p>Returns a callback ID.</p>
<!-- events_onmousemove -->
<p><div class="prop"><span class="title" id="events_onmousemove">events.onmousemove(callback)</span></div>
<div class="tsproto">events.onmousemove(callback: (e: MouseEvent) => void): number</div>
</p>
Registers a callback that is invoked when the mouse is moved over the main screen.
<span class="snip">callback</span> receives a <a href="#MouseEvent">MouseEvent</a> object.
<p>Returns a callback ID.</p>
<!-- MouseEvent -->
<p><div class="prop"><span class="title" id="MouseEvent">MouseEvent</span></div>
</p>
<p>
  <table>
  <tr><td><span class="snip">e.callbackId</span></td><td>ID of the callback associated with the event.</td></tr>
  <tr><td><span class="snip">e.button</span></td><td>The mouse button number. See table below.</td></tr>
  <tr><td><span class="snip">e.x</span></td><td>Cursor X position.</td></tr>
  <tr><td><span class="snip">e.y</span></td><td>Cursor Y position.</td></tr>
  </table>
</p>
<p>
  <table>
  <tr><td><span class="snip">MouseEvent.LEFT</span></td><td>0</td></tr>
  <tr><td><span class="snip">MouseEvent.MIDDLE</span></td><td>1</td></tr>
  <tr><td><span class="snip">MouseEvent.RIGHT</span></td><td>2</td></tr>
  <tr><td><span class="snip">MouseEvent.NONE</span></td><td>-1</td></tr>
  </table>
</p>
<!-- events_remove -->
<p><div class="prop"><span class="title" id="events_remove">events.remove(callbackId)</span></div>
<div class="tsproto">events.remove(callbackId: number): void</div>
</p>
Unregisters the callback specified by <span class="snip">callbackId</span>.
<pre class="ex">
<span class="js-comment">// This callback will only be invoked once</span>
<span class="js-word">events</span>.<span class="js-word">onexec</span>(<span class="js-number">0x802CB1C0</span>, <span class="js-keyword">function</span>(<span class="js-word">e</span>) {
    <span class="js-word">console</span>.<span class="js-word">log</span>(<span class="js-string">"func_802CB1C0 was called"</span>);
    <span class="js-word">events</span>.<span class="js-word">remove</span>(<span class="js-word">e</span>.<span class="js-word">callbackId</span>);
});
</pre>

</div>
<!-- AddressRange -->
<div class="module">
<div class="modtitle"><span class="title" id="AddressRange">AddressRange</span></div>
Address range class
<!-- new_AddressRange -->
<p><div class="prop"><span class="title" id="new_AddressRange">new AddressRange(start, end)</span></div>
<div class="tsproto">new AddressRange(start: number, end: number)</div>
</p>
Creates an immutable object with <span class="snip">start</span> and <span class="snip">end</span> address properties.

<p>The following <span class="snip">AddressRange</span> objects are defined globally&#58;</p>

<table>
<tr><td><span class="snip">ADDR_ANY</span>              </td><td>0x00000000 &#58; 0xFFFFFFFF</td><td>Any address</td></tr>
<tr><td><span class="snip">ADDR_ANY_KUSEG</span>        </td><td>0x00000000 &#58; 0x7FFFFFFF</td><td>MIPS user mode TLB mapped segment</td></tr>
<tr><td><span class="snip">ADDR_ANY_KSEG0</span>        </td><td>0x80000000 &#58; 0x9FFFFFFF</td><td>MIPS cached unmapped segment</td></tr>
<tr><td><span class="snip">ADDR_ANY_KSEG1</span>        </td><td>0xA0000000 &#58; 0xBFFFFFFF</td><td>MIPS uncached unmapped segment</td></tr>
<tr><td><span class="snip">ADDR_ANY_KSEG2</span>        </td><td>0xC0000000 &#58; 0xFFFFFFFF</td><td>MIPS kernel mode TLB mapped segment</td></tr>
<tr><td><span class="snip">ADDR_ANY_RDRAM</span>        </td><td>0x80000000 &#58; 0x807FFFFF</td><td>Cached RDRAM</td></tr>
<tr><td><span class="snip">ADDR_ANY_RDRAM_UNC</span>    </td><td>0xA0000000 &#58; 0xA07FFFFF</td><td>Uncached RDRAM</td></tr>
<tr><td><span class="snip">ADDR_ANY_CART_ROM</span>     </td><td>0x90000000 &#58; 0x95FFFFFF</td><td>Cached cartridge ROM</td></tr>
<tr><td><span class="snip">ADDR_ANY_CART_ROM_UNC</span> </td><td>0xB0000000 &#58; 0xB5FFFFFF</td><td>Uncached cartridge ROM</td></tr>
</table>
<!-- range_size -->
<p><div class="prop"><span class="title" id="range_size">range.size()</span></div>
<div class="tsproto">range.size(): number</div>
</p>
Returns the byte length of the address range (<span class="snip">range.end</span> - <span class="snip">range.start</span> + 1).
<!-- range_includes -->
<p><div class="prop"><span class="title" id="range_includes">range.includes(address)</span></div>
<div class="tsproto">range.includes(address: number): boolean</div>
</p>
Returns <span class="snip">true</span> if <span class="snip">address</span> is within the bounds of the address range.
<!-- range_offset -->
<p><div class="prop"><span class="title" id="range_offset">range.offset(address)</span></div>
<div class="tsproto">range.offset(address: number): number</div>
</p>
Converts <span class="snip">address</span> to an offset and returns the result (<span class="snip">address</span> - <span class="snip">range.start</span>).
<p>Throws an error if <span class="snip">address</span> is out of bounds.</p>
<!-- range_address -->
<p><div class="prop"><span class="title" id="range_address">range.address(offset)</span></div>
<div class="tsproto">range.address(offset: number): number</div>
</p>
Converts <span class="snip">offset</span> to an address and returns the result (<span class="snip">range.start</span> + <span class="snip">offset</span>).
<p>Throws an error if <span class="snip">offset</span> is out of bounds.</p>
<!-- range_start -->
<p><div class="prop"><span class="title" id="range_start">range.start</span></div>
<div class="tsproto">range.start: number</div>
</p>
The start address.
<!-- range_end -->
<p><div class="prop"><span class="title" id="range_end">range.end</span></div>
<div class="tsproto">range.end: number</div>
</p>
The end address.

</div>
<!-- N64Image -->
<div class="module">
<div class="modtitle"><span class="title" id="N64Image">N64Image</span></div>
N64 image class
<!-- new_N64Image -->
<p><div class="prop"><span class="title" id="new_N64Image">new N64Image(width, height[, format [, pixels[, palette]]])</span></div>
<div class="tsproto">new N64Image(width: number, height: number, format?: number = IMG_RGBA32, pixels?: Buffer, palette?: Buffer)</div>
</p>
Creates an <a href="#N64Image">N64Image</a> object.
<p>
<span class="snip">width</span>&#58; Width of the image.<br>
<span class="snip">height</span>&#58; Height of the image.<br>
<span class="snip">format</span>&#58; Optional image format. <span class="snip">IMG_RGBA32</span> by default. See the table below for supported formats.<br>
<span class="snip">pixels</span>&#58; Optional <a target="blank" href="https://nodejs.org/docs/v0.12.1/api/buffer.html">Buffer</a> object containing pixel data.
The byte length must be equal to <span class="snip">(width * height * N64Image.bpp(format)) / 8</span>. Copied to <a href="#image_pixels">image.pixels</a>.<br>
<span class="snip">palette</span>&#58; Optional <a target="blank" href="https://nodejs.org/docs/v0.12.1/api/buffer.html">Buffer</a> object containing palette data. Copied to <a href="#image_palette">image.palette</a>.
</p>
<table>
<thead>
<tr><td>Format</td><td>Pixels</td><td>Palette</td></tr>
</thead>
<tr><td><span class="snip">IMG_RGBA16</span>    </td><td>16-bit colors (r5g5b5a1)            </td><td>(not used)</td></tr>
<tr><td><span class="snip">IMG_RGBA32</span>    </td><td>32-bit colors (r8g8b8a8)            </td><td>(not used)</td></tr>
<tr><td><span class="snip">IMG_CI4_RGBA16</span></td><td>4-bit color indices                 </td><td>16-bit colors (r5g5b5a1)</td></tr>
<tr><td><span class="snip">IMG_CI4_IA16</span>  </td><td>4-bit color indices                 </td><td>16-bit intensity/alpha values (i8a8)</td></tr>
<tr><td><span class="snip">IMG_CI8_RGBA16</span></td><td>8-bit color indices                 </td><td>16-bit colors (r5g5b5a1)</td></tr>
<tr><td><span class="snip">IMG_CI8_IA16</span>  </td><td>8-bit color indices                 </td><td>16-bit intensity/alpha values (i8a8)</td></tr>
<tr><td><span class="snip">IMG_IA4</span>       </td><td>4-bit intensity/alpha values (i3a1) </td><td>(not used)</td></tr>
<tr><td><span class="snip">IMG_IA8</span>       </td><td>8-bit intensity/alpha values (i4a4) </td><td>(not used)</td></tr>
<tr><td><span class="snip">IMG_IA16</span>      </td><td>16-bit intensity/alpha values (i8a8)</td><td>(not used)</td></tr>
<tr><td><span class="snip">IMG_I4</span>        </td><td>4-bit intensity values              </td><td>(not used)</td></tr>
<tr><td><span class="snip">IMG_I8</span>        </td><td>8-bit intensity values              </td><td>(not used)</td></tr>
</table>
<!-- N64Image_fromPNG -->
<p><div class="prop"><span class="title" id="N64Image_fromPNG">N64Image.fromPNG(pngData[, format])</span></div>
<div class="tsproto">N64Image.fromPNG(pngData: Buffer, format?: number = IMG_RGBA32): N64Image</div>
</p>
Static function. Creates an <a href="#N64Image">N64Image</a> object from a PNG file.
<pre class="ex">
<span class="js-keyword">var</span> <span class="js-word">image</span> = <span class="js-word">N64Image</span>.<span class="js-word">fromPNG</span>(<span class="js-word">fs</span>.<span class="js-word">readfile</span>(<span class="js-string">"image.png"</span>));
</pre>
Color quantization is not implemented. An error is thrown if <span class="snip">format</span> is a color-index (CI) type
and the color count of the PNG image exceeds the maximum number of colors supported. The maximum
number of colors supported by the CI4 and CI8 formats are 16 and 256, respectively.
<!-- N64Image_format -->
<p><div class="prop"><span class="title" id="N64Image_format">N64Image.format(gbiFmt, gbiSiz[, gbiTlutFmt])</span></div>
<div class="tsproto">N64Image.format(gbiFmt: number, gbiSiz: number, gbiTlutFmt?: number): number</div>
</p>
<p>Static function. Returns a simplified image format number from a given GBI pixel size and format configuration.
Returns <span class="snip">-1</span> if the configuration is invalid or unsupported. See the table below for supported configurations.</p>
<table>
<thead>
<tr><td><span class="snip">gbiFmt</span>      </td><td><span class="snip">gbiSiz</span>     </td><td><span class="snip">gbiTlutFmt</span> </td><td>Return value</td></tr>
</thead>
<tr><td><span class="snip">G_IM_FMT_RGBA</span> </td><td><span class="snip">G_IM_SIZ_16b</span> </td><td>(not used)   </td><td><span class="snip">IMG_RGBA16</span></td></tr>
<tr><td><span class="snip">G_IM_FMT_RGBA</span> </td><td><span class="snip">G_IM_SIZ_32b</span> </td><td>(not used)   </td><td><span class="snip">IMG_RGBA32</span></td></tr>
<tr><td><span class="snip">G_IM_FMT_CI</span>   </td><td><span class="snip">G_IM_SIZ_4b</span>  </td><td><span class="snip">G_TT_RGBA16</span></td><td><span class="snip">IMG_CI4_RGBA16</span></td></tr>
<tr><td><span class="snip">G_IM_FMT_CI</span>   </td><td><span class="snip">G_IM_SIZ_4b</span>  </td><td><span class="snip">G_TT_IA16</span>  </td><td><span class="snip">IMG_CI4_IA16</span></td></tr>
<tr><td><span class="snip">G_IM_FMT_CI</span>   </td><td><span class="snip">G_IM_SIZ_8b</span>  </td><td><span class="snip">G_TT_RGBA16</span></td><td><span class="snip">IMG_CI8_RGBA16</span></td></tr>
<tr><td><span class="snip">G_IM_FMT_CI</span>   </td><td><span class="snip">G_IM_SIZ_8b</span>  </td><td><span class="snip">G_TT_IA16</span>  </td><td><span class="snip">IMG_CI8_IA16</span></td></tr>
<tr><td><span class="snip">G_IM_FMT_IA</span>   </td><td><span class="snip">G_IM_SIZ_4b</span>  </td><td>(not used)   </td><td><span class="snip">IMG_IA4</span></td></tr>
<tr><td><span class="snip">G_IM_FMT_IA</span>   </td><td><span class="snip">G_IM_SIZ_8b</span>  </td><td>(not used)   </td><td><span class="snip">IMG_IA8</span></td></tr>
<tr><td><span class="snip">G_IM_FMT_IA</span>   </td><td><span class="snip">G_IM_SIZ_16b</span> </td><td>(not used)   </td><td><span class="snip">IMG_IA16</span></td></tr>
<tr><td><span class="snip">G_IM_FMT_I</span>    </td><td><span class="snip">G_IM_SIZ_4b</span>  </td><td>(not used)   </td><td><span class="snip">IMG_I4</span></td></tr>
<tr><td><span class="snip">G_IM_FMT_I</span>    </td><td><span class="snip">G_IM_SIZ_8b</span>  </td><td>(not used)   </td><td><span class="snip">IMG_I8</span></td></tr>
</table>
<!-- N64Image_bpp -->
<p><div class="prop"><span class="title" id="N64Image_bpp">N64Image.bpp(format)</span></div>
<div class="tsproto">N64Image.bpp(format: number): number</div>
</p>
Static function. Returns the number of bits used per pixel for a given image format number or <span class="snip">G_IM_SIZ_*</span> constant. Does not include bits used for palette data.
<pre class="ex">
<span class="js-word">N64Image</span>.<span class="js-word">bpp</span>(<span class="js-word">IMG_CI8_RGBA16</span>); <span class="js-comment">// 8</span>
<span class="js-word">N64Image</span>.<span class="js-word">bpp</span>(<span class="js-word">G_IM_SIZ_16b</span>); <span class="js-comment">// 16</span>
</pre>
<!-- image_toPNG -->
<p><div class="prop"><span class="title" id="image_toPNG">image.toPNG()</span></div>
<div class="tsproto">image.toPNG(): Buffer</div>
</p>
Returns a PNG representation of the image data as a <a target="blank" href="https://nodejs.org/docs/v0.12.1/api/buffer.html">Buffer</a> object.
<pre class="ex">
<span class="js-word">fs</span>.<span class="js-word">writefile</span>(<span class="js-string">"image.png"</span>, <span class="js-word">image</span>.<span class="js-word">toPNG</span>());
</pre>
<!-- image_update -->
<p><div class="prop"><span class="title" id="image_update">image.update()</span></div>
<div class="tsproto">image.update(): void</div>
</p>
Updates the internal bitmap. Should be called after alterations are made to <span class="snip">image.pixels</span> or <span class="snip">image.palette</span>.
<!-- image_format -->
<p><div class="prop"><span class="title" id="image_format">image.format</span></div>
<div class="tsproto">image.format: number</div>
</p>
The format ID. Read-only.
<!-- image_width -->
<p><div class="prop"><span class="title" id="image_width">image.width</span></div>
<div class="tsproto">image.width: number</div>
</p>
Width of the image. Read-only.
<!-- image_height -->
<p><div class="prop"><span class="title" id="image_height">image.height</span></div>
<div class="tsproto">image.height: number</div>
</p>
Height of the image. Read-only.
<!-- image_pixels -->
<p><div class="prop"><span class="title" id="image_pixels">image.pixels</span></div>
<div class="tsproto">image.pixels: Buffer</div>
</p>
The pixel data of the image.
<!-- image_palette -->
<p><div class="prop"><span class="title" id="image_palette">image.palette</span></div>
<div class="tsproto">image.palette: Buffer | null</div>
</p>
The palette data of the image. <span class="snip">null</span> if the image does not use a color-index format.

</div>
<!-- cpu -->
<div class="module">
<div class="modtitle"><span class="title" id="cpu">cpu</span></div>
CPU register interface
<!-- cpu_pc -->
<p><div class="prop"><span class="title" id="cpu_pc">cpu.pc</span></div>
</p>
Variable representing the CPU's program counter.
<!-- cpu_hi -->
<p><div class="prop"><span class="title" id="cpu_hi">cpu.hi</span></div>
</p>
Variable representing the lower 32 bits of the CPU's HI register.
<!-- cpu_lo -->
<p><div class="prop"><span class="title" id="cpu_lo">cpu.lo</span></div>
</p>
Variable representing the lower 32 bits of the CPU's LO register.
<!-- cpu_uhi -->
<p><div class="prop"><span class="title" id="cpu_uhi">cpu.uhi</span></div>
</p>
Variable representing the upper 32 bits of the CPU's HI register.
<!-- cpu_ulo -->
<p><div class="prop"><span class="title" id="cpu_ulo">cpu.ulo</span></div>
</p>
Variable representing the upper 32 bits of the CPU's LO register.
<!-- cpu_gpr__ -->
<p><div class="prop"><span class="title" id="cpu_gpr__">cpu.gpr.r0|at|v0|v1..ra</span></div>
<div><span class="title2">cpu.gpr[0..31]</span></div><div class="tsproto">cpu.gpr.r0|at|v0|v1|a0|a1|a2|a3|t0|t1|t2|t3|t4|t5|t6|t7|s0|s1|s2|s3|s4|s5|s6|s7|t8|t9|k0|k1|gp|sp|fp|ra</div>
</p>
Variables representing the lower 32 bits of the CPU's general purpose registers.
<!-- cpu_ugpr__ -->
<p><div class="prop"><span class="title" id="cpu_ugpr__">cpu.ugpr.r0|at|v0|v1..ra</span></div>
<div><span class="title2">cpu.ugpr[0..31]</span></div><div class="tsproto">cpu.ugpr.r0|at|v0|v1|a0|a1|a2|a3|t0|t1|t2|t3|t4|t5|t6|t7|s0|s1|s2|s3|s4|s5|s6|s7|t8|t9|k0|k1|gp|sp|fp|ra</div>
</p>
Variables representing the upper 32 bits of the CPU's general purpose registers.
<!-- cpu_fpr__ -->
<p><div class="prop"><span class="title" id="cpu_fpr__">cpu.fpr.f0..f31</span></div>
<div><span class="title2">cpu.fpr[0..31]</span></div></p>
Variables representing the CPU's 32-bit floating-point registers.
<!-- cpu_dfpr__ -->
<p><div class="prop"><span class="title" id="cpu_dfpr__">cpu.dfpr.f0..f30</span></div>
<div><span class="title2">cpu.dfpr[0..30]</span></div></p>
Variables representing the CPU's 64-bit floating-point registers.
<!-- cpu_cop0 -->
<p><div class="prop"><span class="title" id="cpu_cop0">cpu.cop0.index..errorepc</span></div>
</p>
<p>Variables representing the CPU's Coprocessor 0 registers.</p>
<table>
<tr><td><span class="snip">cpu.cop0.index</span>       </td><td>Index register.</td></tr>
<tr><td><span class="snip">cpu.cop0.random</span>      </td><td>Random register.</td></tr>
<tr><td><span class="snip">cpu.cop0.entrylo0</span>    </td><td>EntryLo0 register.</td></tr>
<tr><td><span class="snip">cpu.cop0.entrylo1</span>    </td><td>EntryLo1 register.</td></tr>
<tr><td><span class="snip">cpu.cop0.context</span>     </td><td>Context register.</td></tr>
<tr><td><span class="snip">cpu.cop0.pagemask</span>    </td><td>PageMask register.</td></tr>
<tr><td><span class="snip">cpu.cop0.wired</span>       </td><td>Wired register.</td></tr>
<tr><td><span class="snip">cpu.cop0.badvaddr</span>    </td><td>BadVAddr register.</td></tr>
<tr><td><span class="snip">cpu.cop0.count</span>       </td><td>Count register.</td></tr>
<tr><td><span class="snip">cpu.cop0.entryhi</span>     </td><td>EntryHi register.</td></tr>
<tr><td><span class="snip">cpu.cop0.compare</span>     </td><td>Compare register.</td></tr>
<tr><td><span class="snip">cpu.cop0.status</span>      </td><td>Status register.</td></tr>
<tr><td><span class="snip">cpu.cop0.cause</span>       </td><td>Cause register. Generates an interrupt when written.</td></tr>
<tr><td><span class="snip">cpu.cop0.epc</span>         </td><td>EPC register.</td></tr>
<tr><td><span class="snip">cpu.cop0.config</span>      </td><td>Config register.</td></tr>
<tr><td><span class="snip">cpu.cop0.taglo</span>       </td><td>TagLo register.</td></tr>
<tr><td><span class="snip">cpu.cop0.taghi</span>       </td><td>TagHi register.</td></tr>
<tr><td><span class="snip">cpu.cop0.errorepc</span>    </td><td>ErrorEPC register.</td></tr>
</table>

</div>
<!-- debug -->
<div class="module">
<div class="modtitle"><span class="title" id="debug">debug</span></div>
Debugger interface
<!-- debug_breakhere -->
<p><div class="prop"><span class="title" id="debug_breakhere">debug.breakhere([silent])</span></div>
<div class="tsproto">debug.breakhere(silent?: boolean = false): void</div>
</p>
Pauses emulation via the debugger. The CPU commands window is not shown if <span class="snip">silent</span> is true.
<p>
Emulation may be resumed by calling <a href="#debug_resume">debug.resume()</a> or clicking the "Go" button in the CPU commands window.
</p>
<pre class="ex">
<span class="js-comment">// Break if the CPU tries to write 5 to 0x80339EA8</span>
<span class="js-word">events</span>.<span class="js-word">onwrite</span>(<span class="js-number">0x80339EA8</span>, <span class="js-keyword">function</span>(<span class="js-word">e</span>) {
    <span class="js-keyword">if</span>(<span class="js-word">e</span>.<span class="js-word">value</span> == <span class="js-number">5</span>) {
        <span class="js-word">debug</span>.<span class="js-word">breakhere</span>();
    }
});
</pre>
<!-- debug_resume -->
<p><div class="prop"><span class="title" id="debug_resume">debug.resume()</span></div>
<div class="tsproto">debug.resume(): void</div>
</p>
Resumes emulation from a debugger pause.
<!-- debug_step -->
<p><div class="prop"><span class="title" id="debug_step">debug.step()</span></div>
<div class="tsproto">debug.step(): void</div>
</p>
Executes a single CPU command. Does nothing if emulation is not paused by the debugger.
<!-- debug_skip -->
<p><div class="prop"><span class="title" id="debug_skip">debug.skip()</span></div>
<div class="tsproto">debug.skip(): void</div>
</p>
Skips the current CPU command. Useful for preventing or overriding an operation.
<pre class="ex">
<span class="js-comment">// Do not let the CPU write to 0x8033B21E</span>
<span class="js-word">events</span>.<span class="js-word">onwrite</span>(<span class="js-number">0x8033B21E</span>, <span class="js-keyword">function</span>() {
    <span class="js-word">debug</span>.<span class="js-word">skip</span>();
});
</pre>
<!-- debug_showmemory -->
<p><div class="prop"><span class="title" id="debug_showmemory">debug.showmemory(address[, physical])</span></div>
<div class="tsproto">debug.showmemory(address: number, physical?: boolean = false): void</div>
</p>
Shows the memory window at <span class="snip">address</span>. Physical address space is used if <span class="snip">physical</span> is <span class="snip">true</span>.
<!-- debug_showcommands -->
<p><div class="prop"><span class="title" id="debug_showcommands">debug.showcommands(address)</span></div>
<div class="tsproto">debug.showcommands(address: number): void</div>
</p>
Shows the CPU commands window at <span class="snip">address</span>.
<!-- debug_paused -->
<p><div class="prop"><span class="title" id="debug_paused">debug.paused</span></div>
<div class="tsproto">debug.paused: boolean</div>
</p>
<span class="snip">true</span> if emulation is currently paused by the debugger.

</div>
<!-- asm -->
<div class="module">
<div class="modtitle"><span class="title" id="asm">asm</span></div>
ASM utilities
<!-- asm_encode -->
<p><div class="prop"><span class="title" id="asm_encode">asm.encode(command[, address])</span></div>
<div class="tsproto">asm.encode(command: string, address?: number): number</div>
</p>
Encodes a single MIPS R4300i opcode. <span class="snip">address</span> is an optional parameter that may be used to hint the address of the instruction for branch offset calculation.
<p>Returns the opcode as a number.</p>
<pre class="ex">
<span class="js-word">asm</span>.<span class="js-word">encode</span>(<span class="js-string">"nop"</span>);                      <span class="js-comment">// 0x00000000</span>
<span class="js-word">asm</span>.<span class="js-word">encode</span>(<span class="js-string">"addiu sp, sp, -24"</span>);        <span class="js-comment">// 0x27BDFFE8</span>
<span class="js-word">asm</span>.<span class="js-word">encode</span>(<span class="js-string">"b 0x80400000"</span>, <span class="js-number">0x803FFF00</span>); <span class="js-comment">// 0x1000003F</span>
<span class="js-word">asm</span>.<span class="js-word">encode</span>(<span class="js-string">"b 0x80400000"</span>, <span class="js-number">0x80400100</span>); <span class="js-comment">// 0x1000FFBF</span>
</pre>
<!-- asm_decode -->
<p><div class="prop"><span class="title" id="asm_decode">asm.decode(opcode[, address])</span></div>
<div class="tsproto">asm.decode(opcode: number, address?: number): string</div>
</p>
Decodes a single MIPS R4300i opcode. <span class="snip">address</span> is an optional parameter that may be used to hint the address of the instruction for branch address calculation.
<p>Returns a line of assembly code as a string.</p>
<pre class="ex">
<span class="js-word">asm</span>.<span class="js-word">decode</span>(<span class="js-number">0x00000000</span>);             <span class="js-comment">// "NOP"</span>
<span class="js-word">asm</span>.<span class="js-word">decode</span>(<span class="js-number">0x27BDFFE8</span>);             <span class="js-comment">// "ADDIU SP, SP, -0x18"</span>
<span class="js-word">asm</span>.<span class="js-word">decode</span>(<span class="js-number">0x1000003F</span>, <span class="js-number">0x803FFF00</span>); <span class="js-comment">// "B 0x80400000"</span>
<span class="js-word">asm</span>.<span class="js-word">decode</span>(<span class="js-number">0x1000FFBF</span>, <span class="js-number">0x80400100</span>); <span class="js-comment">// "B 0x80400000"</span>
</pre>
<!-- asm_gprname -->
<p><div class="prop"><span class="title" id="asm_gprname">asm.gprname(regIndex)</span></div>
<div class="tsproto">asm.gprname(regIndex: number): string</div>
</p>
Returns the name of the general purpose register specified by <span class="snip">regIndex</span>.
<pre class="ex">
<span class="js-word">asm</span>.<span class="js-word">gprname</span>(<span class="js-number">4</span>); <span class="js-comment">// Returns "a0"</span>
</pre>

</div>
<!-- fs -->
<div class="module">
<div class="modtitle"><span class="title" id="fs">fs</span></div>
File system interface
<!-- fs_open -->
<p><div class="prop"><span class="title" id="fs_open">fs.open(path, mode)</span></div>
<div class="tsproto">fs.open(path: string, mode: string): number</div>
</p>
Opens the file pointed to by <span class="snip">path</span> in the mode specified by <span class="snip">mode</span>.
See <a target="blank" href="https://pubs.opengroup.org/onlinepubs/009604599/functions/fopen.html">fopen</a> for a list of valid modes.
<p>Returns a file descriptor.</p>
<!-- fs_close -->
<p><div class="prop"><span class="title" id="fs_close">fs.close(fd)</span></div>
<div class="tsproto">fs.close(fd): void</div>
</p>
Closes the file referenced by <span class="snip">fd</span>.
<!-- fs_write -->
<p><div class="prop"><span class="title" id="fs_write">fs.write(fd, buffer[, offset[, length[, position]]])</span></div>
<div class="tsproto">fs.write(fd: number, buffer: string | Buffer | ArrayBuffer, offset?: number, length?: number, position?: number): number</div>
</p>
Writes <span class="snip">buffer</span> to the file referenced by file descriptor <span class="snip">fd</span>. <span class="snip">buffer</span> may be one of the following types&#58;
<a target="blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer">ArrayBuffer</a>,
<a target="blank" href="https://nodejs.org/docs/v0.12.1/api/buffer.html">Buffer</a>,
<a target="blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView">DataView</a>,
<a target="blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray">TypedArray</a>, string.
<p>
<span class="snip">offset</span>&#58; Optional position in the source buffer.<br>
<span class="snip">length</span>&#58; Optional maximum number of bytes to write.<br>
<span class="snip">position</span>&#58; Optional file position.
</p>
<p>Returns the number of bytes written.</p>
<pre class="ex">
<span class="js-keyword">var</span> <span class="js-word">fd</span> = <span class="js-word">fs</span>.<span class="js-word">open</span>(<span class="js-string">"file.txt"</span>, <span class="js-string">"wb"</span>);
<span class="js-word">fs</span>.<span class="js-word">write</span>(<span class="js-word">fd</span>, <span class="js-string">"Hello "</span>);
<span class="js-word">fs</span>.<span class="js-word">write</span>(<span class="js-word">fd</span>, <span class="js-string">"world!\n"</span>);
<span class="js-word">fs</span>.<span class="js-word">close</span>(<span class="js-word">fd</span>);
</pre>
<!-- fs_writefile -->
<p><div class="prop"><span class="title" id="fs_writefile">fs.writefile(path, buffer)</span></div>
<div class="tsproto">fs.writefile(path: string, buffer: string | Buffer | ArrayBuffer): void</div>
</p>
Writes <span class="snip">buffer</span> to the file specified by <span class="snip">path</span>.
<pre class="ex">
<span class="js-word">fs</span>.<span class="js-word">writefile</span>(<span class="js-string">"ram_dump.bin"</span>, <span class="js-word">mem</span>.<span class="js-word">getblock</span>(<span class="js-word">K0BASE</span>, <span class="js-word">mem</span>.<span class="js-word">ramSize</span>));
</pre>
<!-- fs_read -->
<p><div class="prop"><span class="title" id="fs_read">fs.read(fd, buffer, offset, length, position)</span></div>
<div class="tsproto">fs.read(fd: number, buffer: Buffer | ArrayBuffer, offset: number, length: number, position: number) : number</div>
</p>
Reads data from the file referenced by <span class="snip">fd</span> into <span class="snip">buffer</span>. <span class="snip">buffer</span> may be one of the following types&#58;
<a target="blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer">ArrayBuffer</a>,
<a target="blank" href="https://nodejs.org/docs/v0.12.1/api/buffer.html">Buffer</a>,
<a target="blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView">DataView</a>,
<a target="blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray">TypedArray</a>.<br><br>
<span class="snip">offset</span>&#58; Position in the source buffer.<br>
<span class="snip">length</span>&#58; Number of bytes to read.<br>
<span class="snip">position</span>&#58; File position.
<p>Returns the number of bytes read.</p>
<!-- fs_readfile -->
<p><div class="prop"><span class="title" id="fs_readfile">fs.readfile(path)</span></div>
<div class="tsproto">fs.readfile(path: string): Buffer</div>
</p>
Returns a <a target="blank" href="https://nodejs.org/docs/v0.12.1/api/buffer.html">Buffer</a> object representing the data of the file specified by <span class="snip">path</span>.
<!-- fs_exists -->
<p><div class="prop"><span class="title" id="fs_exists">fs.exists(path)</span></div>
<div class="tsproto">fs.exists(path: string): boolean</div>
</p>
Returns <span class="snip">true</span> if the path exists.
<!-- fs_fstat -->
<p><div class="prop"><span class="title" id="fs_fstat">fs.fstat(fd)</span></div>
<div class="tsproto">fs.fstat(fd: number): fs.Stats</div>
</p>
Returns an <a href="#fs_Stats">fs.Stats</a> object containing information about the file referenced by <span class="snip">fd</span>.
<!-- fs_stat -->
<p><div class="prop"><span class="title" id="fs_stat">fs.stat(path)</span></div>
<div class="tsproto">fs.stat(path: string): fs.Stats</div>
</p>
Returns an <a href="#fs_Stats">fs.Stats</a> object containing information about the file specified by <span class="snip">path</span>.
<!-- fs_unlink -->
<p><div class="prop"><span class="title" id="fs_unlink">fs.unlink(path)</span></div>
<div class="tsproto">fs.unlink(path: string): boolean</div>
</p>
Deletes the file specified by <span class="snip">path</span>. Returns <span class="snip">true</span> if the operation is successful.
<!-- fs_mkdir -->
<p><div class="prop"><span class="title" id="fs_mkdir">fs.mkdir(path)</span></div>
<div class="tsproto">fs.mkdir(path: string): boolean</div>
</p>
Creates a directory. Returns <span class="snip">true</span> if the operation is successful.
<!-- fs_rmdir -->
<p><div class="prop"><span class="title" id="fs_rmdir">fs.rmdir(path)</span></div>
<div class="tsproto">fs.rmdir(path: string): boolean</div>
</p>
Deletes a directory. The directory must be empty. Returns <span class="snip">true</span> if the operation is successful.
<!-- fs_readdir -->
<p><div class="prop"><span class="title" id="fs_readdir">fs.readdir(path)</span></div>
<div class="tsproto">fs.readdir(path: string): string[]</div>
</p>
Returns an array of file names from a directory.
<!-- fs_Stats -->
<p><div class="prop"><span class="title" id="fs_Stats">fs.Stats</span></div>
</p>
<p>Object containing information about a file or directory. Generated by <a href="#fs_fstat">fs.fstat/fs.stat</a>.</p>
<p>
<table>
<tr><td><span class="snip">stats.dev</span></td><td>ID of the device the file resides on</td></tr>
<tr><td><span class="snip">stats.ino</span></td><td>inode number</td></tr>
<tr><td><span class="snip">stats.mode</span></td><td>File permissions</td></tr>
<tr><td><span class="snip">stats.nlink</span></td><td>Number of links to the file</td></tr>
<tr><td><span class="snip">stats.uid</span></td><td>User ID</td></tr>
<tr><td><span class="snip">stats.gid</span></td><td>Group ID</td></tr>
<tr><td><span class="snip">stats.rdev</span></td><td>Device ID (if file is character or block special)</td></tr>
<tr><td><span class="snip">stats.size</span></td><td>Size of the file in bytes</td></tr>
<tr><td><span class="snip">stats.atimeMs</span></td><td>Last access timestamp in milliseconds</td></tr>
<tr><td><span class="snip">stats.mtimeMs</span></td><td>Last modification timestamp in milliseconds</td></tr>
<tr><td><span class="snip">stats.ctimeMs</span></td><td>Creation timestamp in milliseconds</td></tr>
<tr><td><span class="snip">stats.atime</span></td><td>JS Date object representing the last access time</td></tr>
<tr><td><span class="snip">stats.mtime</span></td><td>JS Date object representing the last modification time</td></tr>
<tr><td><span class="snip">stats.ctime</span></td><td>JS Date object representing the creation time</td></tr>
</table>
</p>

<b>stats.isDirectory()</b><br>
<div class="tsproto">stats.isDirectory(): boolean</div>
<p>Returns <span class="snip">true</span> if the <span class="snip">fs.Stats</span> object describes a directory.</p>

<b>stats.isFile()</b><br>
<div class="tsproto">stats.isFile(): boolean</div>
<p>Returns <span class="snip">true</span> if the <span class="snip">fs.Stats</span> object describes a regular file.</p>

</div>
<!-- Socket -->
<div class="module">
<div class="modtitle"><span class="title" id="Socket">Socket</span></div>
TCP socket class
<!-- new_Socket -->
<p><div class="prop"><span class="title" id="new_Socket">new Socket([options])</span></div>
<div class="tsproto">new Socket(options?: Object)</div>
</p>
<p>Creates a <a href="#Socket">Socket</a> object. <span class="snip">options</span> may contain the following properties:</p>
<table>
<tr><td><span class="snip">allowHalfOpen</span></td><td>If <span class="snip">true</span>, the socket will not automatically fully close when the read half is closed. <span class="snip">false</span> by default.</td></tr>
</table>
<!-- socket_connect -->
<p><div class="prop"><span class="title" id="socket_connect">socket.connect(port, host[, connectListener])</span></div>
<div class="tsproto">socket.connect(port: number, host: string, connectListener?: () => void): void</div>
</p>
Initiates a TCP connection.
Optional <span class="snip">connectListener</span> is invoked when the connection is established (i.e the socket is writable).
<pre class="ex">
<span class="js-keyword">var</span> <span class="js-word">client</span> = <span class="js-keyword">new</span> <span class="js-word">Socket</span>();

<span class="js-word">client</span>.<span class="js-word">connect</span>(<span class="js-number">80</span>, <span class="js-string">'www.example.com'</span>, <span class="js-keyword">function</span>() {
    <span class="js-keyword">var</span> <span class="js-word">response</span> = <span class="js-string">''</span>;

    <span class="js-word">client</span>.<span class="js-word">on</span>(<span class="js-string">'data'</span>, <span class="js-keyword">function</span>(<span class="js-word">data</span>) {
        <span class="js-word">response</span> += <span class="js-word">data</span>.<span class="js-word">toString</span>();
    });

    <span class="js-word">client</span>.<span class="js-word">on</span>(<span class="js-string">'end'</span>, <span class="js-keyword">function</span>() {
        <span class="js-word">console</span>.<span class="js-word">log</span>(<span class="js-word">response</span>);
    });

    <span class="js-keyword">const</span> <span class="js-word">message</span> = [
        <span class="js-string">"GET / HTTP/1.1"</span>,
        <span class="js-string">"Host: www.example.com"</span>,
        <span class="js-string">"Connection: close"</span>,
        <span class="js-string">"\r\n"</span>
    ].<span class="js-word">join</span>(<span class="js-string">"\r\n"</span>);

    <span class="js-word">client</span>.<span class="js-word">end</span>(<span class="js-word">message</span>);
});
</pre>
<!-- socket_write -->
<p><div class="prop"><span class="title" id="socket_write">socket.write(data[, callback])</span></div>
<div class="tsproto">socket.write(data: Buffer | string, callback?: () => void): void</div>
</p>
<p>Sends <span class="snip">data</span> on the socket.</p>
Optional <span class="snip">callback</span> is invoked when all bytes of <span class="snip">data</span> are sent.
<!-- socket_end -->
<p><div class="prop"><span class="title" id="socket_end">socket.end([data[, callback]])</span></div>
<div class="tsproto">socket.end(data?: Buffer | string, callback?: () => void): void</div>
</p>
<p>Sends optional <span class="snip">data</span> and closes the write half of the socket after all buffered writes are sent.</p>
Optional <span class="snip">callback</span> is invoked when all buffered writes are sent and the write half of the socket is closed.
<!-- socket_close -->
<p><div class="prop"><span class="title" id="socket_close">socket.close()</span></div>
<div class="tsproto">socket.close(): void</div>
</p>
Fully closes the socket.
<!-- socket_on_connect -->
<p><div class="prop"><span class="title" id="socket_on_connect">socket.on('connect', listener)</span></div>
<div class="tsproto">socket.on('connect', listener: () => void): Socket</div>
</p>
<p>Registers a listener for the <span class="snip">'connect'</span> event.</p>
<span class="snip">listener</span> is invoked when the connection is established.
<p>Returns the Socket object.</p>
<!-- socket_on_lookup -->
<p><div class="prop"><span class="title" id="socket_on_lookup">socket.on('lookup', listener)</span></div>
<div class="tsproto">socket.on('lookup', listener: (Object) => void): Socket</div>
</p>
<p>Registers a listener for the <span class="snip">'lookup'</span> event.</p>
<p><span class="snip">listener</span> receives an object with the following properties when the host name is resolved:</p>
<table>
<tr><td><span class="snip">err</span></td><td><span class="snip">null</span>, or an <span class="snip">Error</span> object if an error occurred <span style="color:red;">(TODO)</span></td></tr>
<tr><td><span class="snip">address</span></td><td>IP address string</td></tr>
<tr><td><span class="snip">port</span></td><td>Port number</td></tr>
<tr><td><span class="snip">family</span></td><td>"IPv4" or "IPv6"</td></tr>
</table>
<p>Returns the Socket object.</p>
<!-- socket_on_data -->
<p><div class="prop"><span class="title" id="socket_on_data">socket.on('data', listener)</span></div>
<div class="tsproto">socket.on('data', listener: (data: Buffer) => void): Socket</div>
</p>
<p>Registers a listener for the <span class="snip">'data'</span> event.</p>
<span class="snip">listener</span> receives data as a <a target="blank" href="https://nodejs.org/docs/v0.12.1/api/buffer.html">Buffer</a> object.
<p>Returns the Socket object.</p>
<!-- socket_on_end -->
<p><div class="prop"><span class="title" id="socket_on_end">socket.on('end', listener)</span></div>
<div class="tsproto">socket.on('end', listener: () => void): Socket</div>
</p>
<p>Registers a listener for the <span class="snip">'end'</span> event.</p>
<span class="snip">listener</span> is invoked when the other side closes the read half of the socket.
<p>Returns the Socket object.</p>
<!-- socket_on_close -->
<p><div class="prop"><span class="title" id="socket_on_close">socket.on('close', listener)</span></div>
<div class="tsproto">socket.on('close', listener: () => void): Socket</div>
</p>
<p>Registers a listener for the <span class="snip">'close'</span> event.</p>
<span class="snip">listener</span> is invoked when the socket is fully closed.
<p>Returns the Socket object.</p>
<!-- socket_on_drain -->
<p><div class="prop"><span class="title" id="socket_on_drain">socket.on('drain', listener)</span></div>
<div class="tsproto">socket.on('drain', listener: () => void): Socket</div>
</p>
<p>Registers a listener for the <span class="snip">'drain'</span> event.</p>
<span class="snip">listener</span> is invoked when all buffered writes are sent.
<p>Returns the Socket object.</p>
<!-- socket_on_error -->
<p><div class="prop"><span class="title" id="socket_on_error">socket.on('error', listener)</span></div>
<div class="tsproto">socket.on('error', listener: (Error) => void): Socket</div>
</p>
<p>Registers a listener for the <span class="snip">'error'</span> event.</p>
<span class="snip">listener</span> receives an <span class="snip">Error</span> object when an error occurs.
<p>Returns the Socket object.</p>
<!-- socket_off -->
<p><div class="prop"><span class="title" id="socket_off">socket.off(eventName, listener)</span></div>
<div class="tsproto">socket.off(eventName: string, listener: Function): Socket</div>
</p>
Removes a listener.
<p>Returns the Socket object.</p>
<!-- socket_remoteAddress -->
<p><div class="prop"><span class="title" id="socket_remoteAddress">socket.remoteAddress</span></div>
<div class="tsproto">socket.remoteAddress: string</div>
</p>
The remote address. <span class="snip">""</span> if the socket is not connected.
<!-- socket_remotePort -->
<p><div class="prop"><span class="title" id="socket_remotePort">socket.remotePort</span></div>
<div class="tsproto">socket.remotePort: number</div>
</p>
The remote port. <span class="snip">0</span> if the socket is not connected.
<!-- socket_localAddress -->
<p><div class="prop"><span class="title" id="socket_localAddress">socket.localAddress</span></div>
<div class="tsproto">socket.localAddress: string</div>
</p>
The local address. <span class="snip">""</span> if the socket is not connected.
<!-- socket_localPort -->
<p><div class="prop"><span class="title" id="socket_localPort">socket.localPort</span></div>
<div class="tsproto">socket.localPort: number</div>
</p>
The local port. <span class="snip">""</span> if the socket is not connected.
<!-- socket_addressFamily -->
<p><div class="prop"><span class="title" id="socket_addressFamily">socket.addressFamily</span></div>
<div class="tsproto">socket.addressFamily: string</div>
</p>
The address family. <span class="snip">""</span> if the socket is not connected.

</div>
<!-- Server -->
<div class="module">
<div class="modtitle"><span class="title" id="Server">Server</span></div>
TCP server class
<!-- new_Server -->
<p><div class="prop"><span class="title" id="new_Server">new Server()</span></div>
<div class="tsproto">new Server()</div>
</p>
Creates a <a href="#Server">Server</a> object.
<pre class="ex">
<span class="js-keyword">var</span> <span class="js-word">server</span> = <span class="js-keyword">new</span> <span class="js-word">Server</span>();
<span class="js-word">server</span>.<span class="js-word">listen</span>(<span class="js-number">1337</span>, <span class="js-string">"127.0.0.1"</span>);

<span class="js-word">server</span>.<span class="js-word">on</span>(<span class="js-string">'connection'</span>, <span class="js-keyword">function</span>(<span class="js-word">c</span>) {
    <span class="js-word">c</span>.<span class="js-word">on</span>(<span class="js-string">'data'</span>, <span class="js-keyword">function</span>(<span class="js-word">data</span>) {
        <span class="js-keyword">if</span>(<span class="js-word">data</span>.<span class="js-word">toString</span>() == <span class="js-string">'ping'</span>) {
            <span class="js-word">c</span>.<span class="js-word">write</span>(<span class="js-string">'pong'</span>);
        }
    });

    <span class="js-word">c</span>.<span class="js-word">on</span>(<span class="js-string">'end'</span>, <span class="js-keyword">function</span>() {
        <span class="js-word">console</span>.<span class="js-word">log</span>(<span class="js-string">"client ended connection"</span>);
    })
});
</pre>
<!-- server_listen -->
<p><div class="prop"><span class="title" id="server_listen">server.listen(port[, address])</span></div>
<div class="tsproto">server.listen(port: number, address?: string = "0.0.0.0"): void</div>
</p>
Binds the server to the specified port and address and starts listening.
<!-- server_close -->
<p><div class="prop"><span class="title" id="server_close">server.close()</span></div>
<div class="tsproto">server.close(): void</div>
</p>
Stops listening for new connections (does not affect existing connections).
<!-- server_on_connection -->
<p><div class="prop"><span class="title" id="server_on_connection">server.on('connection', listener)</span></div>
<div class="tsproto">server.on('connection', listener: (Socket) => void): Server</div>
</p>
<p>Registers a listener for the <span class="snip">'connection'</span> event.</p>
<span class="snip">listener</span> receives a <a href="#Socket">Socket</a> object when a client has connected.
<p>Returns the Server object.</p>
<!-- server_on_listening -->
<p><div class="prop"><span class="title" id="server_on_listening">server.on('listening', listener)</span></div>
<div class="tsproto">server.on('listening', listener: () => void): Server</div>
</p>
<p>Registers a listener for the <span class="snip">'listening'</span> event.</p>
<span class="snip">listener</span> is invoked when the server begins listening for connections.
<p>Returns the Server object.</p>
<!-- server_on_close -->
<p><div class="prop"><span class="title" id="server_on_close">server.on('close', listener)</span></div>
<div class="tsproto">server.on('close', listener: () => void): Server</div>
</p>
<p>Registers a listener for the <span class="snip">'close'</span> event.</p>
<span class="snip">listener</span> is invoked when the server is closed.
<p>Returns the Server object.</p>
<!-- server_on_error -->
<p><div class="prop"><span class="title" id="server_on_error">server.on('error', listener)</span></div>
<div class="tsproto">server.on('error', listener: (Error) => void): Server</div>
</p>
<p>Registers a listener for the <span class="snip">'error'</span> event.</p>
<span class="snip">listener</span> receives an <span class="snip">Error</span> object when an error occurs.
<p>Returns the Server object.</p>
<!-- server_off -->
<p><div class="prop"><span class="title" id="server_off">server.off(eventName, listener)</span></div>
<div class="tsproto">server.off(eventName: string, listener: Function): Server</div>
</p>
Removes a listener.
<p>Returns the Server object.</p>
<!-- server_port -->
<p><div class="prop"><span class="title" id="server_port">server.port</span></div>
<div class="tsproto">server.port: number</div>
</p>
The bound port number. <span class="snip">0</span> if the server is not listening.
<!-- server_address -->
<p><div class="prop"><span class="title" id="server_address">server.address</span></div>
<div class="tsproto">server.address: string</div>
</p>
The bound address. <span class="snip">""</span> if the server is not listening.
<!-- server_addressFamily -->
<p><div class="prop"><span class="title" id="server_addressFamily">server.addressFamily</span></div>
<div class="tsproto">server.addressFamily: string</div>
</p>
The bound address family. <span class="snip">""</span> if the server is not listening.

</div>
<!-- script -->
<div class="module">
<div class="modtitle"><span class="title" id="script">script</span></div>
Script instance configuration interface
<!-- script_keepalive -->
<p><div class="prop"><span class="title" id="script_keepalive">script.keepalive(keepAlive)</span></div>
<div class="tsproto">script.keepalive(keepAlive: boolean): void</div>
</p>
Prevents the script instance from being destroyed when it has nothing left to do.
Useful when the default console input behavior is desired.
<!-- script_timeout -->
<p><div class="prop"><span class="title" id="script_timeout">script.timeout(milliseconds)</span></div>
<div class="tsproto">script.timeout(milliseconds: number): void</div>
</p>
Sets the maximum amount of time tasks may run on the script instance before errors are thrown. By default this value is 500 milliseconds.
Setting this value to zero will allow tasks to run indefinitely.
<!-- script_abort -->
<p><div class="prop"><span class="title" id="script_abort">script.abort()</span></div>
<div class="tsproto">script.abort(): void</div>
</p>
Terminates the script instance.

</div>
<!-- Globals -->
<div class="module">
<div class="modtitle"><span class="title" id="Globals">Globals</span></div>
<!-- global -->
<p><div class="prop"><span class="title" id="global">global</span></div>
<div class="tsproto">global: Object</div>
</p>
Reference to the global object.
<pre class="ex">
<span class="js-word">global</span>.<span class="js-word">test</span> = <span class="js-number">1</span>;
<span class="js-word">console</span>.<span class="js-word">log</span>(<span class="js-word">test</span>); <span class="js-comment">// "1"</span>
</pre>
<!-- PJ64_JSAPI_VERSION -->
<p><div class="prop"><span class="title" id="PJ64_JSAPI_VERSION">PJ64_JSAPI_VERSION</span></div>
<div class="tsproto">PJ64_JSAPI_VERSION: string</div>
</p>
<p>API major version name.</p>
<table>
<tr><td><span class="snip">"jsapi-2"</span></td><td>Second edition (Project64 4.0+)</td></tr>
<tr><td><span class="snip">undefined</span></td><td><a target="blank" href="https://htmlpreview.github.io/?https://github.com/project64/project64/blob/5d0d9927b1fd91e9647eb799f68e132804de924e/apidoc.htm">First edition</a> (Project64 2.4 to 3.x)</td></tr>
</table>
<pre class="ex">
<span class="js-keyword">if</span> (<span class="js-keyword">typeof</span> <span class="js-word">PJ64_JSAPI_VERSION</span> !== <span class="js-string">'undefined'</span>) {
    <span class="js-comment">// use new API</span>
}
<span class="js-keyword">else</span> {
    <span class="js-comment">// use old API</span>
}
</pre>
See also: <a target="blank" href="https://htmlpreview.github.io/?https://github.com/project64/project64/blob/5d0d9927b1fd91e9647eb799f68e132804de924e/apidoc.htm">First edition documentation</a>
<!-- require -->
<p><div class="prop"><span class="title" id="require">require(id)</span></div>
<div class="tsproto">require(id: string): Object</div>
</p>
Loads a module and returns its <span class="snip">module.exports</span> object. <span class="snip">id</span> may be one of the following:
<p>
<ul>
<li>The name of a JavaScript (*.js) or DLL (*.dll) file in the <span class="snip">Scripts/modules</span> directory.</i>
<li>If <span class="snip">id</span> begins with <span class="snip">./</span> or <span class="snip">../</span>, the path of a JavaScript  or DLL file relative to the calling module's location.</i>
</ul>
</p>
<pre class="ex">
<span class="js-comment">/* Scripts/module_example.js */</span>

<span class="js-keyword">const</span> <span class="js-word">mymodule</span> = <span class="js-word">require</span>(<span class="js-string">'mymodule/lib.js'</span>); <span class="js-comment">// Loads Scripts/modules/mymodule/lib.js</span>
<span class="js-word">mymodule</span>.<span class="js-word">init</span>(); <span class="js-comment">// Prints "Loaded mymodule"</span>
</pre>
<pre class="ex">
<span class="js-comment">/* Scripts/modules/mymodule/lib.js */</span>

<span class="js-keyword">function</span> <span class="js-word">init</span>() {
    <span class="js-word">console</span>.<span class="js-word">log</span>(<span class="js-string">"Loaded mymodule"</span>);
}

<span class="js-word">module</span>.<span class="js-word">exports</span> = {
    <span class="js-word">init</span>: <span class="js-word">init</span>
};
</pre>
<p>Native modules use the <a target="blank" href="https://github.com/svaarala/duktape/blob/master/doc/c-module-convention.rst">Duktape C module convention</a>.</p>
<!-- exec -->
<p><div class="prop"><span class="title" id="exec">exec(command[, options])</span></div>
<div class="tsproto">exec(command: string, options?: Object): string</div>
</p>
Executes a system command. Does not return until the subprocess exits.
<p>Returns the standard output of the subprocess as a string.</p>

<p><span class="snip">options</span> may contain any of the following properties:</p>

<table>
<tr><td><span class="snip">showWindow</span></td><td>If <span class="snip">true</span>, the window of the subprocess is visible. <span class="snip">false</span> by default.</td></tr>
<tr><td><span class="snip">verbose</span></td><td>If <span class="snip">true</span>, the output of the subprocess is sent to the script manager console. <span class="snip">false</span> by default.</td></tr>
<tr><td><span class="snip">cwd</span></td><td>Current working directory of the subprocess. By default this is the directory containing Project64.</td></tr>
</table>

<p>This function throws an error if the operation fails or if the exit code of the subprocess is non-zero.
The thrown error object contains the following properties:</p>

<table>
<tr><td><span class="snip">status</span></td><td>The exit code of the subprocess.</td></tr>
<tr><td><span class="snip">stdout</span></td><td>The standard output of the subprocess.</td></tr>
<tr><td><span class="snip">stderr</span></td><td>The standard error output of the subprocess.</td></tr>
<tr><td><span class="snip">pid</span></td><td>The PID of the subprocess.</td></tr>
</table>
<pre class="ex">
<span class="js-keyword">try</span> {
    <span class="js-word">exec</span>(<span class="js-string">"dir"</span>, { <span class="js-word">verbose</span>: <span class="js-keyword">true</span> });
} <span class="js-keyword">catch</span>(<span class="js-word">err</span>) {
    <span class="js-word">console</span>.<span class="js-word">log</span>(<span class="js-string">"exec() failed with code"</span>, <span class="js-word">err</span>.<span class="js-word">status</span>);
    <span class="js-word">console</span>.<span class="js-word">log</span>(<span class="js-word">err</span>.<span class="js-word">stderr</span>);
}
</pre>
<!-- alert -->
<p><div class="prop"><span class="title" id="alert">alert(message[, caption])</span></div>
<div class="tsproto">alert(message: string, caption?: string): void</div>
</p>
Shows a message box over the main window. Does not return until the message box is dismissed.
<!-- setTimeout -->
<p><div class="prop"><span class="title" id="setTimeout">setTimeout(callback, delay)</span></div>
<div class="tsproto">setTimeout(callback: () => void, delay: number): number</div>
</p>
<span class="snip">callback</span> is invoked once after the number of milliseconds specified by <span class="snip">delay</span>.
<p>Returns a timeout ID.</p>
<!-- clearTimeout -->
<p><div class="prop"><span class="title" id="clearTimeout">clearTimeout(timeoutId)</span></div>
<div class="tsproto">clearTimeout(timeoutId: number): void</div>
</p>
Cancels the timeout specified by <span class="snip">timeoutId</span>.
<!-- setInterval -->
<p><div class="prop"><span class="title" id="setInterval">setInterval(callback, delay)</span></div>
<div class="tsproto">setInterval(callback: () => void, delay: number): number</div>
</p>
<span class="snip">callback</span> is invoked periodically. <span class="snip">delay</span> specifies the amount of time in milliseconds to wait before each invocation.
<p>Returns an interval ID.</p>
<!-- clearInterval -->
<p><div class="prop"><span class="title" id="clearInterval">clearInterval(intervalId)</span></div>
<div class="tsproto">clearInterval(intervalId: number): void</div>
</p>
Cancels the interval specified by <span class="snip">intervalId</span>.
<!-- number_hex -->
<p><div class="prop"><span class="title" id="number_hex">number.hex([numChars])</span></div>
<div class="tsproto">number.hex(numChars?: number): string</div>
</p>
Returns a hexadecimal string representation of the number object.
The returned string is prepended with zeroes so that its character length is <span class="snip">numChars</span> or 8 by default.
<pre class="ex">
<span class="js-keyword">var</span> <span class="js-word">n</span> = <span class="js-number">123</span>;
<span class="js-word">n</span>.<span class="js-word">hex</span>();  <span class="js-comment">// 0000007B</span>
<span class="js-word">n</span>.<span class="js-word">hex</span>(<span class="js-number">4</span>); <span class="js-comment">// 007B</span>
</pre>
<!-- type_ids -->
<p><div class="prop"><span class="title" id="type_ids">Type IDs</span></div>
</p>
<table>
<tr><td><span class="snip">u8</span>  </td><td>Unsigned 8-bit integer</td></tr>
<tr><td><span class="snip">u16</span> </td><td>Unsigned 16-bit integer</td></tr>
<tr><td><span class="snip">u32</span> </td><td>Unsigned 32-bit integer</td></tr>
<tr><td><span class="snip">s8</span>  </td><td>Signed 8-bit integer</td></tr>
<tr><td><span class="snip">s16</span> </td><td>Signed 16-bit integer</td></tr>
<tr><td><span class="snip">s32</span> </td><td>Signed 32-bit integer</td></tr>
<tr><td><span class="snip">f32</span> </td><td>32-bit single precision floating-point</td></tr>
<tr><td><span class="snip">f64</span> </td><td>64-bit double precision floating-point</td></tr>
<tr><td><span class="snip">u64</span> </td><td>Unsigned 64-bit integer</td></tr>
<tr><td><span class="snip">s64</span> </td><td>Signed 64-bit integer</td></tr>
</table>

<p>Note: The <a href="#mem_bindvar">mem.bind*</a>/<a href="#mem_typedef">mem.typedef</a> APIs do not currently support <span class="snip">u64</span> and <span class="snip">s64</span>.</p>
<!-- N64_memory_addresses -->
<p><div class="prop"><span class="title" id="N64_memory_addresses">N64 memory addresses</span></div>
</p>
<p>
  <table>
  <tr><td><span class="snip">RDRAM_CONFIG_REG</span>       </td><td>0xA3F00000</td></tr>
  <tr><td><span class="snip">RDRAM_DEVICE_TYPE_REG</span>  </td><td>0xA3F00000</td></tr>
  <tr><td><span class="snip">RDRAM_DEVICE_ID_REG</span>    </td><td>0xA3F00004</td></tr>
  <tr><td><span class="snip">RDRAM_DELAY_REG</span>        </td><td>0xA3F00008</td></tr>
  <tr><td><span class="snip">RDRAM_MODE_REG</span>         </td><td>0xA3F0000C</td></tr>
  <tr><td><span class="snip">RDRAM_REF_INTERVAL_REG</span> </td><td>0xA3F00010</td></tr>
  <tr><td><span class="snip">RDRAM_REF_ROW_REG</span>      </td><td>0xA3F00014</td></tr>
  <tr><td><span class="snip">RDRAM_RAS_INTERVAL_REG</span> </td><td>0xA3F00018</td></tr>
  <tr><td><span class="snip">RDRAM_MIN_INTERVAL_REG</span> </td><td>0xA3F0001C</td></tr>
  <tr><td><span class="snip">RDRAM_ADDR_SELECT_REG</span>  </td><td>0xA3F00020</td></tr>
  <tr><td><span class="snip">RDRAM_DEVICE_MANUF_REG</span> </td><td>0xA3F00024</td></tr>
  <tr><td><span class="snip">SP_MEM_ADDR_REG</span>        </td><td>0xA4040000</td></tr>
  <tr><td><span class="snip">SP_DRAM_ADDR_REG</span>       </td><td>0xA4040004</td></tr>
  <tr><td><span class="snip">SP_RD_LEN_REG</span>          </td><td>0xA4040008</td></tr>
  <tr><td><span class="snip">SP_WR_LEN_REG</span>          </td><td>0xA404000C</td></tr>
  <tr><td><span class="snip">SP_STATUS_REG</span>          </td><td>0xA4040010</td></tr>
  <tr><td><span class="snip">SP_DMA_FULL_REG</span>        </td><td>0xA4040014</td></tr>
  <tr><td><span class="snip">SP_DMA_BUSY_REG</span>        </td><td>0xA4040018</td></tr>
  <tr><td><span class="snip">SP_SEMAPHORE_REG</span>       </td><td>0xA404001C</td></tr>
  <tr><td><span class="snip">SP_PC_REG</span>              </td><td>0xA4080000</td></tr>
  <tr><td><span class="snip">SP_IBIST_REG</span>           </td><td>0xA4080004</td></tr>
  <tr><td><span class="snip">DPC_START_REG</span>          </td><td>0xA4100000</td></tr>
  <tr><td><span class="snip">DPC_END_REG</span>            </td><td>0xA4100004</td></tr>
  <tr><td><span class="snip">DPC_CURRENT_REG</span>        </td><td>0xA4100008</td></tr>
  <tr><td><span class="snip">DPC_STATUS_REG</span>         </td><td>0xA410000C</td></tr>
  <tr><td><span class="snip">DPC_CLOCK_REG</span>          </td><td>0xA4100010</td></tr>
  <tr><td><span class="snip">DPC_BUFBUSY_REG</span>        </td><td>0xA4100014</td></tr>
  <tr><td><span class="snip">DPC_PIPEBUSY_REG</span>       </td><td>0xA4100018</td></tr>
  <tr><td><span class="snip">DPC_TMEM_REG</span>           </td><td>0xA410001C</td></tr>
  <tr><td><span class="snip">DPS_TBIST_REG</span>          </td><td>0xA4200000</td></tr>
  <tr><td><span class="snip">DPS_TEST_MODE_REG</span>      </td><td>0xA4200004</td></tr>
  <tr><td><span class="snip">DPS_BUFTEST_ADDR_REG</span>   </td><td>0xA4200008</td></tr>
  <tr><td><span class="snip">DPS_BUFTEST_DATA_REG</span>   </td><td>0xA420000C</td></tr>
  <tr><td><span class="snip">MI_INIT_MODE_REG</span>       </td><td>0xA4300000</td></tr>
  <tr><td><span class="snip">MI_MODE_REG</span>            </td><td>0xA4300000</td></tr>
  <tr><td><span class="snip">MI_VERSION_REG</span>         </td><td>0xA4300004</td></tr>
  <tr><td><span class="snip">MI_NOOP_REG</span>            </td><td>0xA4300004</td></tr>
  <tr><td><span class="snip">MI_INTR_REG</span>            </td><td>0xA4300008</td></tr>
  <tr><td><span class="snip">MI_INTR_MASK_REG</span>       </td><td>0xA430000C</td></tr>
  <tr><td><span class="snip">VI_STATUS_REG</span>          </td><td>0xA4400000</td></tr>
  <tr><td><span class="snip">VI_CONTROL_REG</span>         </td><td>0xA4400000</td></tr>
  <tr><td><span class="snip">VI_ORIGIN_REG</span>          </td><td>0xA4400004</td></tr>
  <tr><td><span class="snip">VI_DRAM_ADDR_REG</span>       </td><td>0xA4400004</td></tr>
  <tr><td><span class="snip">VI_WIDTH_REG</span>           </td><td>0xA4400008</td></tr>
  <tr><td><span class="snip">VI_H_WIDTH_REG</span>         </td><td>0xA4400008</td></tr>
  <tr><td><span class="snip">VI_INTR_REG</span>            </td><td>0xA440000C</td></tr>
  <tr><td><span class="snip">VI_V_INTR_REG</span>          </td><td>0xA440000C</td></tr>
  <tr><td><span class="snip">VI_CURRENT_REG</span>         </td><td>0xA4400010</td></tr>
  <tr><td><span class="snip">VI_V_CURRENT_LINE_REG</span>  </td><td>0xA4400010</td></tr>
  <tr><td><span class="snip">VI_BURST_REG</span>           </td><td>0xA4400014</td></tr>
  <tr><td><span class="snip">VI_TIMING_REG</span>          </td><td>0xA4400014</td></tr>
  <tr><td><span class="snip">VI_V_SYNC_REG</span>          </td><td>0xA4400018</td></tr>
  <tr><td><span class="snip">VI_H_SYNC_REG</span>          </td><td>0xA440001C</td></tr>
  <tr><td><span class="snip">VI_LEAP_REG</span>            </td><td>0xA4400020</td></tr>
  <tr><td><span class="snip">VI_H_SYNC_LEAP_REG</span>     </td><td>0xA4400020</td></tr>
  <tr><td><span class="snip">VI_H_START_REG</span>         </td><td>0xA4400024</td></tr>
  <tr><td><span class="snip">VI_H_VIDEO_REG</span>         </td><td>0xA4400024</td></tr>
  <tr><td><span class="snip">VI_V_START_REG</span>         </td><td>0xA4400028</td></tr>
  <tr><td><span class="snip">VI_V_VIDEO_REG</span>         </td><td>0xA4400028</td></tr>
  <tr><td><span class="snip">VI_V_BURST_REG</span>         </td><td>0xA440002C</td></tr>
  <tr><td><span class="snip">VI_X_SCALE_REG</span>         </td><td>0xA4400030</td></tr>
  <tr><td><span class="snip">VI_Y_SCALE_REG</span>         </td><td>0xA4400034</td></tr>
  <tr><td><span class="snip">AI_DRAM_ADDR_REG</span>       </td><td>0xA4500000</td></tr>
  <tr><td><span class="snip">AI_LEN_REG</span>             </td><td>0xA4500004</td></tr>
  <tr><td><span class="snip">AI_CONTROL_REG</span>         </td><td>0xA4500008</td></tr>
  <tr><td><span class="snip">AI_STATUS_REG</span>          </td><td>0xA450000C</td></tr>
  <tr><td><span class="snip">AI_DACRATE_REG</span>         </td><td>0xA4500010</td></tr>
  <tr><td><span class="snip">AI_BITRATE_REG</span>         </td><td>0xA4500014</td></tr>
  <tr><td><span class="snip">PI_DRAM_ADDR_REG</span>       </td><td>0xA4600000</td></tr>
  <tr><td><span class="snip">PI_CART_ADDR_REG</span>       </td><td>0xA4600004</td></tr>
  <tr><td><span class="snip">PI_RD_LEN_REG</span>          </td><td>0xA4600008</td></tr>
  <tr><td><span class="snip">PI_WR_LEN_REG</span>          </td><td>0xA460000C</td></tr>
  <tr><td><span class="snip">PI_STATUS_REG</span>          </td><td>0xA4600010</td></tr>
  <tr><td><span class="snip">PI_BSD_DOM1_LAT_REG</span>    </td><td>0xA4600014</td></tr>
  <tr><td><span class="snip">PI_BSD_DOM1_PWD_REG</span>    </td><td>0xA4600018</td></tr>
  <tr><td><span class="snip">PI_BSD_DOM1_PGS_REG</span>    </td><td>0xA460001C</td></tr>
  <tr><td><span class="snip">PI_BSD_DOM1_RLS_REG</span>    </td><td>0xA4600020</td></tr>
  <tr><td><span class="snip">PI_BSD_DOM2_LAT_REG</span>    </td><td>0xA4600024</td></tr>
  <tr><td><span class="snip">PI_BSD_DOM2_PWD_REG</span>    </td><td>0xA4600028</td></tr>
  <tr><td><span class="snip">PI_BSD_DOM2_PGS_REG</span>    </td><td>0xA460002C</td></tr>
  <tr><td><span class="snip">PI_BSD_DOM2_RLS_REG</span>    </td><td>0xA4600030</td></tr>
  <tr><td><span class="snip">RI_MODE_REG</span>            </td><td>0xA4700000</td></tr>
  <tr><td><span class="snip">RI_CONFIG_REG</span>          </td><td>0xA4700004</td></tr>
  <tr><td><span class="snip">RI_CURRENT_LOAD_REG</span>    </td><td>0xA4700008</td></tr>
  <tr><td><span class="snip">RI_SELECT_REG</span>          </td><td>0xA470000C</td></tr>
  <tr><td><span class="snip">RI_REFRESH_REG</span>         </td><td>0xA4700010</td></tr>
  <tr><td><span class="snip">RI_COUNT_REG</span>           </td><td>0xA4700010</td></tr>
  <tr><td><span class="snip">RI_LATENCY_REG</span>         </td><td>0xA4700014</td></tr>
  <tr><td><span class="snip">RI_RERROR_REG</span>          </td><td>0xA4700018</td></tr>
  <tr><td><span class="snip">RI_WERROR_REG</span>          </td><td>0xA470001C</td></tr>
  <tr><td><span class="snip">SI_DRAM_ADDR_REG</span>       </td><td>0xA4800000</td></tr>
  <tr><td><span class="snip">SI_PIF_ADDR_RD64B_REG</span>  </td><td>0xA4800004</td></tr>
  <tr><td><span class="snip">SI_PIF_ADDR_WR64B_REG</span>  </td><td>0xA4800010</td></tr>
  <tr><td><span class="snip">SI_STATUS_REG</span>          </td><td>0xA4800018</td></tr>
  </table>
</p>
<p>
    <table>
    <tr><td><span class="snip">PIF_ROM_START</span> </td><td>0xBFC00000</td></tr>
    <tr><td><span class="snip">PIF_RAM_START</span> </td><td>0xBFC007C0</td></tr>
    <tr><td><span class="snip">SP_DMEM_START</span> </td><td>0xA4000000</td></tr>
    <tr><td><span class="snip">SP_IMEM_START</span> </td><td>0xA4001000</td></tr>
    </table>
</p>
<p>
    <table>
    <tr><td><span class="snip">KUBASE</span>  </td><td>0x00000000</td></tr>
    <tr><td><span class="snip">K0BASE</span>  </td><td>0x80000000</td></tr>
    <tr><td><span class="snip">K1BASE</span>  </td><td>0xA0000000</td></tr>
    <tr><td><span class="snip">K2BASE</span>  </td><td>0xC0000000</td></tr>
    </table>
</p>
<p>
    <table>
    <tr><td><span class="snip">UT_VEC</span>  </td><td>0x80000000</td></tr>
    <tr><td><span class="snip">R_VEC</span>   </td><td>0xBFC00000</td></tr>
    <tr><td><span class="snip">XUT_VEC</span> </td><td>0x80000080</td></tr>
    <tr><td><span class="snip">ECC_VEC</span> </td><td>0x80000100</td></tr>
    <tr><td><span class="snip">E_VEC</span>   </td><td>0x80000180</td></tr>
    </table>
</p>
<!-- Miscellaneous -->
<p><div class="prop"><span class="title" id="Miscellaneous">Miscellaneous</span></div>
</p>
<p>
  <table>
  <tr><td><span class="snip">M_GFXTASK</span></td><td>1</td></tr>
  <tr><td><span class="snip">M_AUDTASK</span></td><td>2</td></tr>
  </table>
</p>
<p>
  <table>
  <tr><td><span class="snip">OS_READ</span></td><td>0</td></tr>
  <tr><td><span class="snip">OS_WRITE</span></td><td>1</td></tr>
  </table>
</p>
<p>
  <table>
  <tr><td><span class="snip">G_IM_FMT_RGBA</span></td><td>0</td></tr>
  <tr><td><span class="snip">G_IM_FMT_YUV</span></td><td>1</td></tr>
  <tr><td><span class="snip">G_IM_FMT_CI</span></td><td>2</td></tr>
  <tr><td><span class="snip">G_IM_FMT_IA</span></td><td>3</td></tr>
  <tr><td><span class="snip">G_IM_FMT_I</span></td><td>4</td></tr>
  </table>
</p>
<p>
  <table>
  <tr><td><span class="snip">G_IM_SIZ_4b</span></td><td>0</td></tr>
  <tr><td><span class="snip">G_IM_SIZ_8b</span></td><td>1</td></tr>
  <tr><td><span class="snip">G_IM_SIZ_16b</span></td><td>2</td></tr>
  <tr><td><span class="snip">G_IM_SIZ_32b</span></td><td>3</td></tr>
  </table>
</p>
<p>
  <table>
  <tr><td><span class="snip">G_TT_NONE</span>  </td><td>0x0000</td></tr>
  <tr><td><span class="snip">G_TT_RGBA16</span></td><td>0x8000</td></tr>
  <tr><td><span class="snip">G_TT_IA16</span>  </td><td>0xC000</td></tr>
  </table>
</p>

</div>
</div>
</body>
